plugins_xmp_metadata.js.html 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>plugins/xmp_metadata.js - Documentation</title>
  6. <script src="scripts/prettify/prettify.js"></script>
  7. <script src="scripts/prettify/lang-css.js"></script>
  8. <!--[if lt IE 9]>
  9. <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
  10. <![endif]-->
  11. <link type="text/css" rel="stylesheet" href="styles/prettify.css">
  12. <link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
  13. </head>
  14. <body>
  15. <input type="checkbox" id="nav-trigger" class="nav-trigger" />
  16. <label for="nav-trigger" class="navicon-button x">
  17. <div class="navicon"></div>
  18. </label>
  19. <label for="nav-trigger" class="overlay"></label>
  20. <nav>
  21. <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="jsPDF.html">jsPDF</a></li></ul><h3>Global</h3><ul><li><a href="global.html#addFont">addFont</a></li><li><a href="global.html#addHTML">addHTML</a></li><li><a href="global.html#addMetadata">addMetadata</a></li><li><a href="global.html#addPage">addPage</a></li><li><a href="global.html#autoPrint">autoPrint</a></li><li><a href="global.html#CapJoinStyles">CapJoinStyles</a></li><li><a href="global.html#circle">circle</a></li><li><a href="global.html#ellipse">ellipse</a></li><li><a href="global.html#getFontList">getFontList</a></li><li><a href="global.html#lines">lines</a></li><li><a href="global.html#lstext">lstext</a></li><li><a href="global.html#output">output</a></li><li><a href="global.html#rect">rect</a></li><li><a href="global.html#roundedRect">roundedRect</a></li><li><a href="global.html#save">save</a></li><li><a href="global.html#setDisplayMode">setDisplayMode</a></li><li><a href="global.html#setDrawColor">setDrawColor</a></li><li><a href="global.html#setFillColor">setFillColor</a></li><li><a href="global.html#setFont">setFont</a></li><li><a href="global.html#setFontSize">setFontSize</a></li><li><a href="global.html#setFontStyle">setFontStyle</a></li><li><a href="global.html#setLineCap">setLineCap</a></li><li><a href="global.html#setLineJoin">setLineJoin</a></li><li><a href="global.html#setLineWidth">setLineWidth</a></li><li><a href="global.html#setPage">setPage</a></li><li><a href="global.html#setProperties">setProperties</a></li><li><a href="global.html#setTextColor">setTextColor</a></li><li><a href="global.html#text">text</a></li><li><a href="global.html#triangle">triangle</a></li></ul>
  22. </nav>
  23. <div id="main">
  24. <h1 class="page-title">plugins/xmp_metadata.js</h1>
  25. <section>
  26. <article>
  27. <pre class="prettyprint source linenums"><code>/** ====================================================================
  28. * jsPDF XMP metadata plugin
  29. * Copyright (c) 2016 Jussi Utunen, u-jussi@suomi24.fi
  30. *
  31. * Permission is hereby granted, free of charge, to any person obtaining
  32. * a copy of this software and associated documentation files (the
  33. * "Software"), to deal in the Software without restriction, including
  34. * without limitation the rights to use, copy, modify, merge, publish,
  35. * distribute, sublicense, and/or sell copies of the Software, and to
  36. * permit persons to whom the Software is furnished to do so, subject to
  37. * the following conditions:
  38. *
  39. * The above copyright notice and this permission notice shall be
  40. * included in all copies or substantial portions of the Software.
  41. *
  42. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  43. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  44. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  45. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  46. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  47. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  48. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  49. * ====================================================================
  50. */
  51. /*global jsPDF */
  52. /**
  53. * Adds XMP formatted metadata to PDF
  54. *
  55. * @param {String} metadata The actual metadata to be added. The metadata shall be stored as XMP simple value. Note that if the metadata string contains XML markup characters "&lt;", ">" or "&amp;", those characters should be written using XML entities.
  56. * @param {String} namespaceuri Sets the namespace URI for the metadata. Last character should be slash or hash.
  57. * @function
  58. * @returns {jsPDF}
  59. * @methodOf jsPDF#
  60. * @name addMetadata
  61. */
  62. (function (jsPDFAPI) {
  63. 'use strict';
  64. var xmpmetadata = "";
  65. var xmpnamespaceuri = "";
  66. var metadata_object_number = "";
  67. jsPDFAPI.addMetadata = function (metadata,namespaceuri) {
  68. xmpnamespaceuri = namespaceuri || "http://jspdf.default.namespaceuri/"; //The namespace URI for an XMP name shall not be empty
  69. xmpmetadata = metadata;
  70. this.internal.events.subscribe(
  71. 'postPutResources',
  72. function () {
  73. if(!xmpmetadata)
  74. {
  75. metadata_object_number = "";
  76. }
  77. else
  78. {
  79. var xmpmeta_beginning = '&lt;x:xmpmeta xmlns:x="adobe:ns:meta/">';
  80. var rdf_beginning = '&lt;rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">&lt;rdf:Description rdf:about="" xmlns:jspdf="' + xmpnamespaceuri + '">&lt;jspdf:metadata>';
  81. var rdf_ending = '&lt;/jspdf:metadata>&lt;/rdf:Description>&lt;/rdf:RDF>';
  82. var xmpmeta_ending = '&lt;/x:xmpmeta>';
  83. var utf8_xmpmeta_beginning = unescape(encodeURIComponent(xmpmeta_beginning));
  84. var utf8_rdf_beginning = unescape(encodeURIComponent(rdf_beginning));
  85. var utf8_metadata = unescape(encodeURIComponent(xmpmetadata));
  86. var utf8_rdf_ending = unescape(encodeURIComponent(rdf_ending));
  87. var utf8_xmpmeta_ending = unescape(encodeURIComponent(xmpmeta_ending));
  88. var total_len = utf8_rdf_beginning.length + utf8_metadata.length + utf8_rdf_ending.length + utf8_xmpmeta_beginning.length + utf8_xmpmeta_ending.length;
  89. metadata_object_number = this.internal.newObject();
  90. this.internal.write('&lt;&lt; /Type /Metadata /Subtype /XML /Length ' + total_len + ' >>');
  91. this.internal.write('stream');
  92. this.internal.write(utf8_xmpmeta_beginning + utf8_rdf_beginning + utf8_metadata + utf8_rdf_ending + utf8_xmpmeta_ending);
  93. this.internal.write('endstream');
  94. this.internal.write('endobj');
  95. }
  96. }
  97. );
  98. this.internal.events.subscribe(
  99. 'putCatalog',
  100. function () {
  101. if (metadata_object_number) {
  102. this.internal.write('/Metadata ' + metadata_object_number + ' 0 R');
  103. }
  104. }
  105. );
  106. return this;
  107. };
  108. }(jsPDF.API));
  109. </code></pre>
  110. </article>
  111. </section>
  112. </div>
  113. <br class="clear">
  114. <footer>
  115. Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.2</a> on Sun Oct 09 2016 11:08:27 GMT+0100 (BST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
  116. </footer>
  117. <script>prettyPrint();</script>
  118. <script src="scripts/linenumber.js"></script>
  119. </body>
  120. </html>