1
1
/** @preserve
2
2
* 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
5
5
*
6
6
* Copyright (c) 2010-2014 James Hall, https://github.com/MrRio/jsPDF
7
7
* 2010 Aaron Spike, https://github.com/acspike
@@ -1693,9 +1693,9 @@ var jsPDF = (function(global) {
1693
1693
* pdfdoc.mymethod() // <- !!!!!!
1694
1694
*/
1695
1695
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" ;
1697
1697
1698
- if ( typeof define === 'function' ) {
1698
+ if ( typeof define === 'function' && define . amd ) {
1699
1699
define ( function ( ) {
1700
1700
return jsPDF ;
1701
1701
} ) ;
@@ -1719,6 +1719,7 @@ var jsPDF = (function(global) {
1719
1719
* Renders an HTML element to canvas object which added as an image to the PDF
1720
1720
*
1721
1721
* This PlugIn requires html2canvas: https://github.com/niklasvh/html2canvas
1722
+ * OR rasterizeHTML: https://github.com/cburgmer/rasterizeHTML.js
1722
1723
*
1723
1724
* @public
1724
1725
* @function
@@ -1735,8 +1736,10 @@ var jsPDF = (function(global) {
1735
1736
jsPDFAPI . addHTML = function ( element , x , y , options , callback ) {
1736
1737
'use strict' ;
1737
1738
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' ) ;
1740
1743
1741
1744
if ( typeof x !== 'number' ) {
1742
1745
options = x ;
@@ -1748,27 +1751,73 @@ var jsPDF = (function(global) {
1748
1751
options = null ;
1749
1752
}
1750
1753
1754
+ var I = this . internal , K = I . scaleFactor , W = I . pageSize . width , H = I . pageSize . height ;
1755
+
1751
1756
options = options || { } ;
1752
- options . onrendered = function ( canvas ) {
1757
+ options . onrendered = function ( obj ) {
1753
1758
x = parseInt ( x ) || 0 ;
1754
1759
y = parseInt ( y ) || 0 ;
1755
1760
var dim = options . dim || { } ;
1756
1761
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 ;
1758
1763
1759
1764
var format = 'JPEG' ;
1760
1765
if ( options . format )
1761
1766
format = options . format ;
1762
1767
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' ] ;
1765
1796
1766
- this . addImage . apply ( this , args ) ;
1797
+ this . addImage . apply ( this , args ) ;
1767
1798
1768
- callback ( w , h , alias , args ) ;
1799
+ callback ( w , h , alias , args ) ;
1800
+ }
1769
1801
} . bind ( this ) ;
1770
1802
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 ;
1772
1821
} ;
1773
1822
} ) ( jsPDF . API ) ;
1774
1823
/** @preserve
@@ -5004,10 +5053,10 @@ jsPDFAPI.putTotalPages = function(pageExpression) {
5004
5053
/*! @source http://purl.eligrey.com/github/Blob.js/blob/master/Blob.js */
5005
5054
5006
5055
if ( ! ( 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 ) {
5009
5057
"use strict" ;
5010
5058
5059
+ view . URL = view . URL || view . webkitURL ;
5011
5060
var BlobBuilder = view . BlobBuilder || view . WebKitBlobBuilder || view . MozBlobBuilder || view . MSBlobBuilder || ( function ( view ) {
5012
5061
var
5013
5062
get_class = function ( object ) {
0 commit comments