123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <title>plugins/addhtml.js - Documentation</title>
- <script src="scripts/prettify/prettify.js"></script>
- <script src="scripts/prettify/lang-css.js"></script>
- <!--[if lt IE 9]>
- <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
- <![endif]-->
- <link type="text/css" rel="stylesheet" href="styles/prettify.css">
- <link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
- </head>
- <body>
- <input type="checkbox" id="nav-trigger" class="nav-trigger" />
- <label for="nav-trigger" class="navicon-button x">
- <div class="navicon"></div>
- </label>
- <label for="nav-trigger" class="overlay"></label>
- <nav>
- <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>
- </nav>
- <div id="main">
-
- <h1 class="page-title">plugins/addhtml.js</h1>
-
-
-
- <section>
- <article>
- <pre class="prettyprint source linenums"><code>/**
- * jsPDF addHTML PlugIn
- * Copyright (c) 2014 Diego Casorran
- *
- * Licensed under the MIT License.
- * http://opensource.org/licenses/mit-license
- */
- (function (jsPDFAPI) {
- 'use strict';
- /**
- * Renders an HTML element to canvas object which added to the PDF
- *
- * This feature requires [html2canvas](https://github.com/niklasvh/html2canvas)
- * or [rasterizeHTML](https://github.com/cburgmer/rasterizeHTML.js)
- *
- * @returns {jsPDF}
- * @name addHTML
- * @param element {Mixed} HTML Element, or anything supported by html2canvas.
- * @param x {Number} starting X coordinate in jsPDF instance's declared units.
- * @param y {Number} starting Y coordinate in jsPDF instance's declared units.
- * @param options {Object} Additional options, check the code below.
- * @param callback {Function} to call when the rendering has finished.
- * NOTE: Every parameter is optional except 'element' and 'callback', in such
- * case the image is positioned at 0x0 covering the whole PDF document
- * size. Ie, to easily take screenshots of webpages saving them to PDF.
- * @deprecated This is being replace with a vector-supporting API. See
- * [this link](https://cdn.rawgit.com/MrRio/jsPDF/master/examples/html2pdf/showcase_supported_html.html)
- */
- jsPDFAPI.addHTML = function (element, x, y, options, callback) {
- 'use strict';
- if(typeof html2canvas === 'undefined' && typeof rasterizeHTML === 'undefined')
- throw new Error('You need either '
- +'https://github.com/niklasvh/html2canvas'
- +' or https://github.com/cburgmer/rasterizeHTML.js');
- if(typeof x !== 'number') {
- options = x;
- callback = y;
- }
- if(typeof options === 'function') {
- callback = options;
- options = null;
- }
- var I = this.internal, K = I.scaleFactor, W = I.pageSize.width, H = I.pageSize.height;
- options = options || {};
- options.onrendered = function(obj) {
- x = parseInt(x) || 0;
- y = parseInt(y) || 0;
- var dim = options.dim || {};
- var h = dim.h || 0;
- var w = dim.w || Math.min(W,obj.width/K) - x;
- var format = 'JPEG';
- if(options.format)
- format = options.format;
- if(obj.height > H && options.pagesplit) {
- var crop = function() {
- var cy = 0;
- while(1) {
- var canvas = document.createElement('canvas');
- canvas.width = Math.min(W*K,obj.width);
- canvas.height = Math.min(H*K,obj.height-cy);
- var ctx = canvas.getContext('2d');
- ctx.drawImage(obj,0,cy,obj.width,canvas.height,0,0,canvas.width,canvas.height);
- var args = [canvas, x,cy?0:y,canvas.width/K,canvas.height/K, format,null,'SLOW'];
- this.addImage.apply(this, args);
- cy += canvas.height;
- if(cy >= obj.height) break;
- this.addPage();
- }
- callback(w,cy,null,args);
- }.bind(this);
- if(obj.nodeName === 'CANVAS') {
- var img = new Image();
- img.onload = crop;
- img.src = obj.toDataURL("image/png");
- obj = img;
- } else {
- crop();
- }
- } else {
- var alias = Math.random().toString(35);
- var args = [obj, x,y,w,h, format,alias,'SLOW'];
- this.addImage.apply(this, args);
- callback(w,h,alias,args);
- }
- }.bind(this);
- if(typeof html2canvas !== 'undefined' && !options.rstz) {
- return html2canvas(element, options);
- }
- if(typeof rasterizeHTML !== 'undefined') {
- var meth = 'drawDocument';
- if(typeof element === 'string') {
- meth = /^http/.test(element) ? 'drawURL' : 'drawHTML';
- }
- options.width = options.width || (W*K);
- return rasterizeHTML[meth](element, void 0, options).then(function(r) {
- options.onrendered(r.image);
- }, function(e) {
- callback(null,e);
- });
- }
- return null;
- };
- })(jsPDF.API);
- </code></pre>
- </article>
- </section>
- </div>
- <br class="clear">
- <footer>
- 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.
- </footer>
- <script>prettyPrint();</script>
- <script src="scripts/linenumber.js"></script>
- </body>
- </html>
|