11/** @preserve
22 * jsPDF - PDF Document creation from JavaScript
3- * Version 1.0.133 -git Built on 2014-05-13T00:23
4- * CommitID 4952bd270a
3+ * Version 1.0.138 -git Built on 2014-05-18T18:42
4+ * CommitID 99b632ed34
55 *
66 * Copyright (c) 2010-2014 James Hall, https://github.com/MrRio/jsPDF
77 * 2010 Aaron Spike, https://github.com/acspike
@@ -1693,9 +1693,9 @@ var jsPDF = (function(global) {
16931693 * pdfdoc.mymethod() // <- !!!!!!
16941694 */
16951695 jsPDF . API = { events :[ ] } ;
1696- jsPDF . version = "1.0.133 -debug 2014-05-13T00:23 :diegocr" ;
1696+ jsPDF . version = "1.0.138 -debug 2014-05-18T18:42 :diegocr" ;
16971697
1698- if ( typeof define === 'function' ) {
1698+ if ( typeof define === 'function' && define . amd ) {
16991699 define ( function ( ) {
17001700 return jsPDF ;
17011701 } ) ;
@@ -1719,6 +1719,7 @@ var jsPDF = (function(global) {
17191719 * Renders an HTML element to canvas object which added as an image to the PDF
17201720 *
17211721 * This PlugIn requires html2canvas: https://github.com/niklasvh/html2canvas
1722+ * OR rasterizeHTML: https://github.com/cburgmer/rasterizeHTML.js
17221723 *
17231724 * @public
17241725 * @function
@@ -1735,8 +1736,10 @@ var jsPDF = (function(global) {
17351736 jsPDFAPI . addHTML = function ( element , x , y , options , callback ) {
17361737 'use strict' ;
17371738
1738- if ( typeof html2canvas === 'undefined' )
1739- throw new Error ( 'You need this: https://github.com/niklasvh/html2canvas' ) ;
1739+ if ( typeof html2canvas === 'undefined' && typeof rasterizeHTML === 'undefined' )
1740+ throw new Error ( 'You need either '
1741+ + 'https://github.com/niklasvh/html2canvas'
1742+ + ' or https://github.com/cburgmer/rasterizeHTML.js' ) ;
17401743
17411744 if ( typeof x !== 'number' ) {
17421745 options = x ;
@@ -1748,27 +1751,73 @@ var jsPDF = (function(global) {
17481751 options = null ;
17491752 }
17501753
1754+ var I = this . internal , K = I . scaleFactor , W = I . pageSize . width , H = I . pageSize . height ;
1755+
17511756 options = options || { } ;
1752- options . onrendered = function ( canvas ) {
1757+ options . onrendered = function ( obj ) {
17531758 x = parseInt ( x ) || 0 ;
17541759 y = parseInt ( y ) || 0 ;
17551760 var dim = options . dim || { } ;
17561761 var h = dim . h || 0 ;
1757- var w = dim . w || Math . min ( this . internal . pageSize . width , canvas . width / this . internal . scaleFactor ) - x ;
1762+ var w = dim . w || Math . min ( W , obj . width / K ) - x ;
17581763
17591764 var format = 'JPEG' ;
17601765 if ( options . format )
17611766 format = options . format ;
17621767
1763- var alias = Math . random ( ) . toString ( 35 ) ;
1764- var args = [ canvas , x , y , w , h , format , alias , 'SLOW' ] ;
1768+ if ( obj . height > H && options . pagesplit ) {
1769+ var crop = function ( ) {
1770+ var cy = 0 ;
1771+ while ( 1 ) {
1772+ var canvas = document . createElement ( 'canvas' ) ;
1773+ canvas . width = Math . min ( W * K , obj . width ) ;
1774+ canvas . height = Math . min ( H * K , obj . height - cy ) ;
1775+ var ctx = canvas . getContext ( '2d' ) ;
1776+ ctx . drawImage ( obj , 0 , cy , obj . width , canvas . height , 0 , 0 , canvas . width , canvas . height ) ;
1777+ var args = [ canvas , x , cy ?0 :y , canvas . width / K , canvas . height / K , format , null , 'SLOW' ] ;
1778+ this . addImage . apply ( this , args ) ;
1779+ cy += canvas . height ;
1780+ if ( cy >= obj . height ) break ;
1781+ this . addPage ( ) ;
1782+ }
1783+ callback ( w , cy , null , args ) ;
1784+ } . bind ( this ) ;
1785+ if ( obj . nodeName === 'CANVAS' ) {
1786+ var img = new Image ( ) ;
1787+ img . onload = crop ;
1788+ img . src = obj . toDataURL ( "image/png" ) ;
1789+ obj = img ;
1790+ } else {
1791+ crop ( ) ;
1792+ }
1793+ } else {
1794+ var alias = Math . random ( ) . toString ( 35 ) ;
1795+ var args = [ obj , x , y , w , h , format , alias , 'SLOW' ] ;
17651796
1766- this . addImage . apply ( this , args ) ;
1797+ this . addImage . apply ( this , args ) ;
17671798
1768- callback ( w , h , alias , args ) ;
1799+ callback ( w , h , alias , args ) ;
1800+ }
17691801 } . bind ( this ) ;
17701802
1771- return html2canvas ( element , options ) ;
1803+ if ( typeof html2canvas !== 'undefined' && ! options . rstz ) {
1804+ return html2canvas ( element , options ) ;
1805+ }
1806+
1807+ if ( typeof rasterizeHTML !== 'undefined' ) {
1808+ var meth = 'drawDocument' ;
1809+ if ( typeof element === 'string' ) {
1810+ meth = / ^ h t t p / . test ( element ) ? 'drawURL' : 'drawHTML' ;
1811+ }
1812+ options . width = options . width || ( W * K ) ;
1813+ return rasterizeHTML [ meth ] ( element , void 0 , options ) . then ( function ( r ) {
1814+ options . onrendered ( r . image ) ;
1815+ } , function ( e ) {
1816+ callback ( null , e ) ;
1817+ } ) ;
1818+ }
1819+
1820+ return null ;
17721821 } ;
17731822} ) ( jsPDF . API ) ;
17741823/** @preserve
@@ -5004,10 +5053,10 @@ jsPDFAPI.putTotalPages = function(pageExpression) {
50045053/*! @source http://purl.eligrey.com/github/Blob.js/blob/master/Blob.js */
50055054
50065055if ( ! ( typeof Blob === "function" || typeof Blob === "object" ) || typeof URL === "undefined" )
5007- if ( ( typeof Blob === "function" || typeof Blob === "object" ) && typeof webkitURL !== "undefined" ) self . URL = webkitURL ;
5008- else var Blob = ( function ( view ) {
5056+ window . Blob = ( function ( view ) {
50095057 "use strict" ;
50105058
5059+ view . URL = view . URL || view . webkitURL ;
50115060 var BlobBuilder = view . BlobBuilder || view . WebKitBlobBuilder || view . MozBlobBuilder || view . MSBlobBuilder || ( function ( view ) {
50125061 var
50135062 get_class = function ( object ) {
0 commit comments