forked from dhx/jsPDF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jspdf.min.js
executable file
·32 lines (31 loc) · 11.2 KB
/
jspdf.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*
jsPDF ( 2012-06-20T18:34 commit ID adc6311628c28b5502cae5bd123bb7958772158c )
Copyright (c) 2010 James Hall, https://github.com/MrRio/jsPDF
Copyright (c) 2012 Willow Systems Corporation, willow-systems.com
MIT license.
jsPDF addImage plugin (JPEG only at this time)
Copyright (c) 2012 https://github.com/siefkenj/
*/
var jsPDF=function(){function x(a,k,c){a="undefined"===typeof a?"p":a.toString().toLowerCase();"undefined"===typeof k&&(k="mm");"undefined"===typeof c&&(c="a4");var l=c.toString().toLowerCase(),i=[],j=0,p={a3:[841.89,1190.55],a4:[595.28,841.89],a5:[420.94,595.28],letter:[612,792],legal:[612,1008]},o="0 g",r=0,f=2,s=!1,u=[],B=[],w=[],D={},I="helvetica",J="normal",E,m,y,d,t={},K=16,o="0 g",L=0,M=0,n={},O=new N(n);if("pt"==k)d=1;else if("mm"==k)d=72/25.4;else if("cm"==k)d=72/2.54;else if("in"==k)d=72;
else throw"Invalid unit: "+k;if(l in p)m=p[l][1]/d,y=p[l][0]/d;else try{m=c[1],y=c[0]}catch(S){throw"Invalid format: "+c;}if("p"===a||"portrait"===a)a="p";else if("l"===a||"landscape"===a)a="l",a=y,y=m,m=a;else throw"Invalid orientation: "+a;var h=function(e){return e.toFixed(2)},q=function(e){return e.toFixed(3)},C=function(e){var b=e.toFixed(0);return 10>e?"0"+b:b},b=function(e){s?u[r].push(e):(i.push(e),j+=e.length+1)},z=function(){f++;B[f]=j;b(f+" 0 obj");return f},Q=function(e){b("stream");b(e);
b("endstream")},a=function(e,b,g,a){var d="F"+(w.length+1).toString(10);w.push({key:d,number:f,name:e,fontName:b,type:g});D[b]===a&&(D[b]={});D[b][g]=d},R=function(){r++;s=!0;u[r]=[];b(h(0.200025*d)+" w");b("0 G");0!==L&&b(L.toString(10)+" J");0!==M&&b(M.toString(10)+" j")},F=function(e,b,g){var a;try{a=D[e][b]}catch(d){a=g}if(!a)throw Error("Unable to look up font label for font '"+e+"', '"+b+"'. Refer to getFontList() for available fonts.");return a},P=function(){s=!1;i=[];B=[];b("%PDF-1.3");var e=
y*d,a=m*d,g,c;for(g=1;g<=r;g++)z(),b("<</Type /Page"),b("/Parent 1 0 R"),b("/Resources 2 0 R"),b("/Contents "+(f+1)+" 0 R>>"),b("endobj"),c=u[g].join("\n"),z(),b("<</Length "+c.length+">>"),Q(c),b("endobj");B[1]=j;b("1 0 obj");b("<</Type /Pages");g="/Kids [";for(c=0;c<r;c++)g+=3+2*c+" 0 R ";b(g+"]");b("/Count "+r);b("/MediaBox [0 0 "+h(e)+" "+h(a)+"]");b(">>");b("endobj");e=0;for(a=w.length;e<a;e++)g=w[e],z(),g.number=f,b("<</BaseFont/"+g.name+"/Type/Font"),b("/Subtype/Type1>>"),b("endobj");O.publish("putResources");
B[2]=j;b("2 0 obj");b("<<");b("/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]");b("/Font <<");for(e=0;e<w.length;e++)b("/"+w[e].key+" "+w[e].number+" 0 R");b(">>");b("/XObject <<");O.publish("putXobjectDict");b(">>");b(">>");b("endobj");z();b("<<");b("/Producer (jsPDF 20120619)");void 0!=t.title&&b("/Title ("+v(t.title)+")");void 0!=t.subject&&b("/Subject ("+v(t.subject)+")");void 0!=t.author&&b("/Author ("+v(t.author)+")");void 0!=t.keywords&&b("/Keywords ("+v(t.keywords)+")");void 0!=t.creator&&
b("/Creator ("+v(t.creator)+")");e=new Date;b("/CreationDate (D:"+[e.getFullYear(),C(e.getMonth()+1),C(e.getDate()),C(e.getHours()),C(e.getMinutes()),C(e.getSeconds())].join("")+")");b(">>");b("endobj");z();b("<<");b("/Type /Catalog");b("/Pages 1 0 R");b("/OpenAction [3 0 R /FitH null]");b("/PageLayout /OneColumn");b(">>");b("endobj");e=j;b("xref");b("0 "+(f+1));b("0000000000 65535 f ");for(a=1;a<=f;a++)g=B[a].toFixed(0),g=10>g.length?Array(11-g.length).join("0")+g:g,b(g+" 00000 n ");b("trailer");
b("<<");b("/Size "+(f+1));b("/Root "+f+" 0 R");b("/Info "+(f-1)+" 0 R");b(">>");b("startxref");b(e);b("%%EOF");s=!0;return i.join("\n")},v=function(e){return e.replace(/\\/g,"\\\\").replace(/\(/g,"\\(").replace(/\)/g,"\\)")},G=function(e){var b="S";if("F"===e)b="f";else if("FD"===e||"DF"===e)b="B";return b};n.internal={pdfEscape:v,getStyle:G,getFont:F,btoa:A,write:function(e,a,g,d){b(1===arguments.length?arguments[0]:Array.prototype.join.call(arguments," "))},getCoordinateString:function(e){return h(e*
d)},getVerticalCoordinateString:function(e){return h((m-e)*d)},collections:{},newObject:z,putStream:Q,events:O,scaleFactor:d,pageSize:{width:y,height:m}};n.addPage=function(){R();return this};n.text=function(e,a,g){"string"===typeof g&&g.match(/[\n\r]/)&&(g=g.split(/\r\n|\r|\n/g));if("string"===typeof g)g=v(g);else if(g instanceof Array){for(var g=g.concat(),c=g.length-1;-1!==c;c--)g[c]=v(g[c]);g=g.join(") Tj\nT* (")}else throw Error('Type of text must be string or Array. "'+g+'" is not recognized.');
b("BT\n/"+E+" "+K+" Tf\n"+K+" TL\n"+o+"\n"+h(e*d)+" "+h((m-a)*d)+" Td\n("+g+") Tj\nET");return this};n.line=function(e,a,g,c){b(h(e*d)+" "+h((m-a)*d)+" m "+h(g*d)+" "+h((m-c)*d)+" l S");return this};n.lines=function(e,a,g,c,f){f=G(f);c=void 0===c?[1,1]:c;b(q(e*d)+" "+q((m-a)*d)+" m ");for(var h=c[0],c=c[1],k=0,i=g.length,j,l,n,p,o=a;k<i;k++)a=g[k],2===a.length?(e=a[0]*h+e,o=a[1]*c+o,b(q(e*d)+" "+q((m-o)*d)+" l")):(j=a[0]*h+e,l=a[1]*c+o,n=a[2]*h+e,p=a[3]*c+o,e=a[4]*h+e,o=a[5]*c+o,b(q(j*d)+" "+q((m-
l)*d)+" "+q(n*d)+" "+q((m-p)*d)+" "+q(e*d)+" "+q((m-o)*d)+" c"));b(f);return this};n.rect=function(e,a,g,c,f){f=G(f);b([h(e*d),h((m-a)*d),h(g*d),h(-c*d),"re",f].join(" "));return this};n.triangle=function(e,a,b,c,d,f,h){this.lines(e,b,[[b-e,c-a],[d-b,f-c],[e-d,a-f]],[1,1],h);return this};n.ellipse=function(e,a,c,f,k){var k=G(k),i=4/3*(Math.SQRT2-1)*c,j=4/3*(Math.SQRT2-1)*f;b([h((e+c)*d),h((m-a)*d),"m",h((e+c)*d),h((m-(a-j))*d),h((e+i)*d),h((m-(a-f))*d),h(e*d),h((m-(a-f))*d),"c"].join(" "));b([h((e-
i)*d),h((m-(a-f))*d),h((e-c)*d),h((m-(a-j))*d),h((e-c)*d),h((m-a)*d),"c"].join(" "));b([h((e-c)*d),h((m-(a+j))*d),h((e-i)*d),h((m-(a+f))*d),h(e*d),h((m-(a+f))*d),"c"].join(" "));b([h((e+i)*d),h((m-(a+f))*d),h((e+c)*d),h((m-(a+j))*d),h((e+c)*d),h((m-a)*d),"c",k].join(" "));return this};n.circle=function(a,b,c,d){return this.ellipse(a,b,c,c,d)};n.setProperties=function(a){t=a;return this};n.addImage=function(){return this};n.setFontSize=function(a){K=a;return this};n.setFont=function(a){a=a.toLowerCase();
E=F(a,J);I=a;return this};n.setFontType=function(a){a=a.toLowerCase();E=F(I,a);J=a;return this};n.getFontList=function(){return{HELVETICA:["normal","bold","italic","bolditalic"],TIMES:["normal","bold","italic","bolditalic"],COURIER:["normal","bold","italic","bolditalic"]}};n.setLineWidth=function(a){b((a*d).toFixed(2)+" w");return this};n.setDrawColor=function(a,c,d){a=0===a&&0===c&&0===d||"undefined"===typeof c?q(a/255)+" G":[q(a/255),q(c/255),q(d/255),"RG"].join(" ");b(a);return this};n.setFillColor=
function(a,c,d){a=0===a&&0===c&&0===d||"undefined"===typeof c?q(a/255)+" g":[q(a/255),q(c/255),q(d/255),"rg"].join(" ");b(a);return this};n.setTextColor=function(a,b,c){o=0===a&&0===b&&0===c||"undefined"===typeof b?q(a/255)+" g":[q(a/255),q(b/255),q(c/255),"rg"].join(" ");return this};n.CapJoinStyles={"0":0,butt:0,but:0,bevel:0,1:1,round:1,rounded:1,circle:1,2:2,projecting:2,project:2,square:2,milter:2};n.setLineCap=function(a,c){var d=this.CapJoinStyles[a];if(d===c)throw Error("Line cap style of '"+
a+"' is not recognized. See or extend .CapJoinStyles property for valid styles");L=d;b(d.toString(10)+" J")};n.setLineJoin=function(a,c){var d=this.CapJoinStyles[a];if(d===c)throw Error("Line join style of '"+a+"' is not recognized. See or extend .CapJoinStyles property for valid styles");M=d;b(d.toString(10)+" j")};n.output=function(a){switch(a){case void 0:return P();case "datauristring":case "dataurlstring":return"data:application/pdf;base64,"+A(P());case "datauri":case "dataurl":document.location.href=
"data:application/pdf;base64,"+A(P());break;default:throw Error('Output type "'+a+'" is not supported.');}};a("Helvetica","helvetica","normal");a("Helvetica-Bold","helvetica","bold");a("Helvetica-Oblique","helvetica","italic");a("Helvetica-BoldOblique","helvetica","bolditalic");a("Courier","courier","normal");a("Courier-Bold","courier","bold");a("Courier-Oblique","courier","italic");a("Courier-BoldOblique","courier","bolditalic");a("Times-Roman","times","normal");a("Times-Bold","times","bold");a("Times-Italic",
"times","italic");a("Times-BoldItalic","times","bolditalic");E=F(I,J);R();if(x.API){var a=x.API,H;for(H in a)a.hasOwnProperty(H)&&(n[H]=a[H])}return n}if("undefined"===typeof A)var A=function(a){var k="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".split(""),c,l,i,j,p=0,o=0,r="",r=[];do c=a.charCodeAt(p++),l=a.charCodeAt(p++),i=a.charCodeAt(p++),j=c<<16|l<<8|i,c=j>>18&63,l=j>>12&63,i=j>>6&63,j&=63,r[o++]=k[c]+k[l]+k[i]+k[j];while(p<a.length);r=r.join("");a=a.length%3;return(a?
r.slice(0,a-3):r)+"===".slice(a||3)};var N=function(a){this.topics={};this.context=a;this.publish=function(a,c,l,i){if(this.topics[a]){var j=this.topics[a],p=Array.prototype.slice.call(arguments,1),o=[],r,f,s,u;f=0;for(s=j.length;f<s;f++)u=j[f],r=u[0],u[1]&&(u[0]=function(){},o.push(f)),r.apply(this.context,p);f=0;for(s=o.length;f<s;f++)j.splice(o[f],1)}};this.subscribe=function(a,c,l){this.topics[a]?this.topics[a].push([c,l]):this.topics[a]=[[c,l]];return{topic:a,callback:c}};this.unsubscribe=function(a){if(this.topics[a.topic])for(var c=
this.topics[a.topic],l=0,i=c.length;l<i;l++)c[l][0]===a.callback&&c.splice(l,1)}};x.API={};return x}();
(function(x){var A=function(){var a=this.internal.collections.addImage_images,k;for(k in a){var c=a[k],l=this.internal.newObject(),i=this.internal.write,j=this.internal.putStream;c.n=l;i("<</Type /XObject");i("/Subtype /Image");i("/Width "+c.w);i("/Height "+c.h);"Indexed"===c.cs?i("/ColorSpace [/Indexed /DeviceRGB "+(c.pal.length/3-1)+" "+(l+1)+" 0 R]"):(i("/ColorSpace /"+c.cs),"DeviceCMYK"===c.cs&&i("/Decode [1 0 1 0 1 0 1 0]"));i("/BitsPerComponent "+c.bpc);"f"in c&&i("/Filter /"+c.f);"dp"in c&&
i("/DecodeParms <<"+c.dp+">>");if("trns"in c&&c.trns.constructor==Array)for(var p="",o=0;o<c.trns.length;o++)p+=c[p][o]+" "+c.trns[o]+" ",i("/Mask ["+p+"]");"smask"in c&&i("/SMask "+(l+1)+" 0 R");i("/Length "+c.data.length+">>");j(c.data);i("endobj")}},N=function(){var a=this.internal.collections.addImage_images,k=this.internal.write,c,l;for(l in a)c=a[l],k("/I"+c.i,c.n,"0","R")};x.addImage=function(a,k,c,l,i,j){if("JPEG"!==k.toUpperCase())throw Error("addImage currently only supports format 'JPEG', not '"+
k+"'");var p,k=this.internal.collections.addImage_images,o=this.internal.getCoordinateString,r=this.internal.getVerticalCoordinateString;if(k)if(Object.keys)p=Object.keys(k).length;else{var f=k,s=0;for(p in f)f.hasOwnProperty(p)&&s++;p=s}else p=0,this.internal.collections.addImage_images=k={},this.internal.events.subscribe("putResources",A),this.internal.events.subscribe("putXobjectDict",N);a:{if(255===!a.charCodeAt(0)||216===!a.charCodeAt(1)||255===!a.charCodeAt(2)||224===!a.charCodeAt(3)||74===
!a.charCodeAt(6)||70===!a.charCodeAt(7)||73===!a.charCodeAt(8)||70===!a.charCodeAt(9)||0===!a.charCodeAt(10))throw Error("getJpegSize requires a binary jpeg file");for(var s=256*a.charCodeAt(4)+a.charCodeAt(5),f=4,u=a.length;f<u;){f+=s;if(255!==a.charCodeAt(f))throw Error("getJpegSize could not find the size of the image");if(192===a.charCodeAt(f+1)){s=256*a.charCodeAt(f+5)+a.charCodeAt(f+6);f=256*a.charCodeAt(f+7)+a.charCodeAt(f+8);f=[f,s];break a}f+=2;s=256*a.charCodeAt(f)+a.charCodeAt(f+1)}f=void 0}a=
{w:f[0],h:f[1],cs:"DeviceRGB",bpc:8,f:"DCTDecode",i:p,data:a};k[p]=a;!i&&!j&&(j=i=-96);0>i&&(i=-72*a.w/i/this.internal.scaleFactor);0>j&&(j=-72*a.h/j/this.internal.scaleFactor);0===i&&(i=j*a.w/a.h);0===j&&(j=i*a.h/a.w);this.internal.write("q",o(i),"0 0",o(j),o(c),r(l+j),"cm /I"+a.i,"Do Q");return this}})(jsPDF.API);