/* * Bytescout PDF Generator SDK for Javascript 1.16.152 - FREE version * All rights reserved. Copyright (c) ByteScout 2011-2016, last updated March 29, 2016 (now throws BytescoutPDFFatalError on invalid images) * http://www.bytescout.com * Free for non-commercial use. To purchase commercial license please visit * http://bytescout.com/products/developer/pdfgeneratorsdkjs/index.html * Use on commercial sites or for commercial purposes is prohibited without a purchase license. */ function BytescoutPDFFatalError(){Error.apply(this,arguments);this.name="BytescoutPDFFatalError"}BytescoutPDFFatalError.prototype=Object.create(Error.prototype); function BytescoutPDF(){this.ForceJPEGForImages=this.showBytescoutLink=this.stopOnInvalidImages=!0;this.JPEGQuality=.95;this.private_objects=[];this.private_info=this.private_add(new PDFInfo);this.private_catalog=this.private_add(new PDFCatalog);this.private_pages=this.private_add(new PDFPages);this.private_outlines=this.private_add(new PDFOutlines);this.private_catalog.setPages(this.private_pages);this.private_catalog.setOutline(this.private_outlines);this.private_anchors=[];this.private_currentPage= void 0;this.private_pageWidth=BytescoutPDF.private_PageSizes[BytescoutPDF.A4].w;this.private_pageHeight=BytescoutPDF.private_PageSizes[BytescoutPDF.A4].h;this.private_isPortrait=!0;this.private_box=void 0;this.private_padding={left:0,top:0,right:0,bottom:0};this.private_textAlign=0;this.private_interline=2;this.private_textState=new PDFTextState;this.private_fonts=[];this.private_lineColor=new PDFColor(0,0,0);this.private_lineWidth="1";this.private_lineEndType=0;this.private_alpha=1;this.private_images= [];this.private_imageIndex=-1;this.private_imageBackgroundColor=new PDFColor(255,255,255);this.private_onHeader=this.private_onFooter=void 0}BytescoutPDF.CRLF="\r\n";BytescoutPDF.A0=0;BytescoutPDF.A1=1;BytescoutPDF.A2=2;BytescoutPDF.A3=3;BytescoutPDF.A4=4;BytescoutPDF.A5=5;BytescoutPDF.A6=6;BytescoutPDF.A7=7;BytescoutPDF.Letter=8;BytescoutPDF.Legal=9;BytescoutPDF.Executive=10;BytescoutPDF.JisB5=11; BytescoutPDF.private_PageSizes=[{w:33.125,h:46.75},{w:23.375,h:33.125},{w:16.5,h:23.375},{w:11.75,h:16.5},{w:8.25,h:11.75},{w:5.875,h:8.25},{w:4.125,h:5.875},{w:2.875,h:4.125},{w:8.5,h:11},{w:8.5,h:14},{w:7.25,h:10.5},{w:7.125,h:10.125}];BytescoutPDF.prototype.private_add=function(a){this.private_objects.push(a);a.id=this.private_objects.length;return a};BytescoutPDF.prototype.pageSetSize=function(a){a=BytescoutPDF.private_PageSizes[a];this.private_pageWidth=a.w;this.private_pageHeight=a.h}; BytescoutPDF.prototype.pageSetWidth=function(a){this.private_pageWidth=a};BytescoutPDF.prototype.pageSetHeight=function(a){this.private_pageHeight=a};BytescoutPDF.PORTRAIT=0;BytescoutPDF.LANDSCAPE=1;BytescoutPDF.prototype.pageSetOrientation=function(a){this.private_isPortrait=a==BytescoutPDF.PORTRAIT};BytescoutPDF.prototype.onFooter=function(a){this.private_onFooter=a};BytescoutPDF.prototype.onHeader=function(a){this.private_onHeader=a}; BytescoutPDF.prototype.pageAdd=function(){this.private_currentPage=new PDFPage(this,this.private_pageWidth,this.private_pageHeight,this.private_isPortrait,this.private_pages);this.private_add(this.private_currentPage);this.private_pages.addPage(this.private_currentPage);var a=new PDFStream;this.private_add(a);this.private_currentPage.setStream(a);void 0!==this.private_onHeader&&this.private_onHeader(this)};BytescoutPDF.prototype.private_pageSetCurrent=function(a){this.private_currentPage=a}; BytescoutPDF.prototype.pageSetIndex=function(a){this.private_currentPage=this.private_pages.getPage(a-1)};BytescoutPDF.prototype.pageGetIndex=function(){return this.private_pages.getIndex(this.private_currentPage)+1};BytescoutPDF.prototype.pageGetCount=function(){return this.private_pages.getCount()};BytescoutPDF.prototype.propertiesSet=function(a,b,c,d,e){this.private_info.set(a,b,c,d,e)};BytescoutPDF.prototype.fontSetName=function(a){this.private_textState.fontSetName(a)}; BytescoutPDF.prototype.fontSetSize=function(a){this.private_textState.fontSetSize(a)};BytescoutPDF.prototype.fontSetStyle=function(a,b,c){this.private_textState.fontSetStyle(a,b,c)};BytescoutPDF.prototype.fontSetStyle=function(a,b,c,d){this.private_textState.fontSetStyle(a,b,c,d)};BytescoutPDF.prototype.fontSetColor=function(a,b,c){this.private_textState.setColor(new PDFColor(a,b,c))};BytescoutPDF.LEFT=0;BytescoutPDF.JUSTIFIED=1;BytescoutPDF.RIGHT=2;BytescoutPDF.CENTER=3; BytescoutPDF.prototype.textSetAlign=function(a){this.private_textAlign=a;void 0!==this.private_box&&this.private_box.setAlign(a)};BytescoutPDF.prototype.setInterline=function(a){this.private_interline=a;void 0!==this.private_box&&this.private_box.setInterline(a)};BytescoutPDF.prototype.textSetBoxPadding=function(a,b,c,d){this.private_padding=void 0===b?{left:a,top:a,right:a,bottom:a}:{left:a,top:b,right:c,bottom:d}}; BytescoutPDF.prototype.textSetBox=function(a,b,c,d){var e=this.private_padding;this.private_box=new PDFBox(this.private_currentPage,a+e.left,b+e.top,c-e.left-e.right,d-e.top-e.bottom,this.private_textAlign,this.private_interline)};BytescoutPDF.prototype.addLink=function(a,b,c,d,e){a=new PDFLink({x:a,y:this.private_currentPage.h-b,width:a+c,height:this.private_currentPage.h-b-d},e);this.private_add(a);this.private_currentPage.addLink(a)}; BytescoutPDF.prototype.textSetLinkStyle=function(a,b,c,d){this.private_textState.setLinkStyle(a,new PDFColor(b,c,d))};BytescoutPDF.prototype.addAnchor=function(a,b,c){this.private_anchors.push({name:a.toLowerCase(),page:b,offset:c})};BytescoutPDF.prototype.addBookmark=function(a,b,c){b=null==a?new PDFBookmark(this.private_outlines,b,c):new PDFBookmark(a,b,c);this.private_add(b);null==a?this.private_outlines.addBookmark(b):a.addBookmark(b);return b}; BytescoutPDF.prototype.private_setFont=function(a){var b=a.getFontName();if(null!=b){var c=null,d;for(d=0;d>2,c=(c&3)<<4|d>>4,g=(d&15)<<2|e>>6,h=e&63,isNaN(d)?g=h=64:isNaN(e)&&(h=64),b=b+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(f)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(c)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(g)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(h); return b};function PDFObject(a,b){this.type=a;this.offset=void 0;this.props=[];this.stream=void 0;void 0!==a&&this.props.push(new PDFProperty("/Type",a));void 0!==b&&(this.value=b)}PDFObject.prototype.addProperty=function(a){this.props.push(a)};PDFObject.prototype.getRef=function(){return""+this.id+" 0 R"}; PDFObject.prototype.getText=function(a){var b;b=""+(this.id+" 0 obj"+BytescoutPDF.CRLF);b+="<<";for(var c=0;c>"+BytescoutPDF.CRLF;void 0!=this.stream&&(b+="stream"+BytescoutPDF.CRLF+this.stream+BytescoutPDF.CRLF+"endstream"+BytescoutPDF.CRLF);void 0!=this.value&&(b+=this.value+BytescoutPDF.CRLF);return b+="endobj"+BytescoutPDF.CRLF}; function PDFProperty(a,b){this.name=a;this.props=[];b instanceof PDFObject?this.reference=b:void 0!==b&&(this.value=b)}PDFProperty.prototype.add=function(a){this.props.push(a)};PDFProperty.prototype.getText=function(a){var b;b=""+(this.name+" ");if(void 0!==this.value)b+=this.value;else if(void 0!==this.reference)b+=this.reference.getRef();else if(0>"}return b};PDFCatalog.prototype=new PDFObject; PDFCatalog.prototype.constructor=PDFCatalog;function PDFCatalog(){PDFObject.call(this,"/Catalog");this.addProperty(new PDFProperty("/Markings"," <>"))}PDFCatalog.prototype.setOutline=function(a){this.outlines=a;this.addProperty(new PDFProperty("/Outlines",a))};PDFCatalog.prototype.setPages=function(a){this.addProperty(new PDFProperty("/Pages",a))}; PDFCatalog.prototype.getText=function(a){0\-\&])/g,"\\$&"),d?"gi":"g"),"string"==typeof c?c.replace(/\$/g,"$$$$"):c)} function NormalizeTextStringToPDFString(a){a=replaceAll(a,"\\","\\\\",!1);a=replaceAll(a,"(","\\(",!1);a=replaceAll(a,")","\\)",!1);a=replaceAll(a,"<","<",!0);a=replaceAll(a,">",">",!0);a=replaceAll(a,""",'"',!0);a=replaceAll(a,"&","&",!0);a=replaceAll(a,"'","'",!0);for(var b="",c=0;cd||159d.maxX&&(d.maxX=f.x);f.yd.maxY&&(d.maxY=f.y)}return d}; PDFPage.prototype.nchars=function(a,b,c,d,e,f){for(var g=d,h=!1,k=a;gd&&g=d){for(d=b;dGenerated by Bytescout PDF Generator SDK 1.12.134'),a.fontSetColor(0,0,0));a.private_pageSetCurrent(this);void 0!==a.private_onFooter&&a.private_onFooter(a);for(var b=0;b>"));if(0this.maxFontSize&&(this.maxFontSize=b.fontSize)}; PDFBufferedLine.prototype.countWords=function(){for(var a=0,b=0;b=a?a:a.charCodeAt(0)-65+10;for(var b=0,c=1,d=a.length-1;0<=d;d--)b+=this.fromHex(a.substr(d,1))*c,c*=16;return b};PDFColor.prototype.getFloat=function(a){return(a/255).toString()}; PDFColor.prototype.getFloatRGB=function(){return this.getFloat(this.r)+" "+this.getFloat(this.g)+" "+this.getFloat(this.b)};PDFImage.prototype=new PDFObject;PDFImage.prototype.constructor=PDFImage;function PDFImage(){PDFObject.call(this,"/XObject");this.loaded=!1} PDFImage.prototype.scanCanvas=function(a){a=a.getImageData(0,0,this.width,this.height);for(var b=4*this.width,c=[],d=0;df&&(f=1);1>g&&(g=1);1>h&&(h=1);c.push(String.fromCharCode(parseInt(f,10)));c.push(String.fromCharCode(parseInt(g,10)));c.push(String.fromCharCode(parseInt(h,10)))}this.stream=c.join("");if(this.stream.length>this.width*this.height*3)throw new BytescoutPDFFatalError("bytescoutpdf.js error: utf-8 encoded image data!"); this.loaded=!0};PDFImage.prototype.writeImage=function(a){this.stream=a;this.loaded=!0}; PDFImage.prototype.getText=function(a){if(isNaN(this.width)||void 0==this.width||isNaN(this.height)||void 0==this.height)return void 0!=console&&console.log("image object: skipping writing of the object id="+this.id+" because width or height is NaN or undefined"),"";this.addProperty(new PDFProperty("/Subtype","/Image"));this.addProperty(new PDFProperty("/Width",this.width));this.addProperty(new PDFProperty("/Height",this.height));this.addProperty(new PDFProperty("/ColorSpace","/DeviceRGB"));"jpg"!= this.format&&"jpeg"!=this.format||this.addProperty(new PDFProperty("/Filter","/DCTDecode"));this.addProperty(new PDFProperty("/BitsPerComponent",8));this.addProperty(new PDFProperty("/Length",this.stream.length));this.addProperty(new PDFProperty("/Name","/Im"+this.id));return PDFObject.prototype.getText.call(this,a)};function extractInfoFromBase64DataURI(a){return/^data:([\w]+?\/([\w]+?));base64,(.+?)$/g.exec(a)}PDFImageFromUrl.prototype=new PDFImage;PDFImageFromUrl.prototype.constructor=PDFImageFromUrl; function PDFImageFromUrl(a,b,c){usejpeg=!0;jpegcompression=.95;"undefined"!==typeof b&&(usejpeg=b.ForceJPEGForImages,jpegcompression=b.JPEGQuality);var d=a.split(".").pop(),d=d.toLowerCase();usejpeg&&(d="jpg");PDFImage.call(this);this.fileName=a;this.badImage=this.loaded=!1;var e=this.img=new Image,f=this;c=document.createElement("CANVAS");c.style.visibility="hidden";c.style.position="absolute";document.body.appendChild(c);this.errorImage=function(){f.badImage=!0;if(void 0!=console&&(console.log("error while loading image from: "+ f.fileName),b.stopOnInvalidImages))throw new BytescoutPDFFatalError("CRITICAL ERROR: Image object is invalid, can not load from"+f.fileName);b.private_onload()};this.loadImage=function(){f.badImage=!1;f.width=e.width;f.height=e.height;f.format=d;c.width=f.width;c.height=f.height;var a=c.getContext("2d"),h=b.private_imageBackgroundColor;a.fillStyle="rgb("+h.r+","+h.g+","+h.b+")";a.fillRect(0,0,e.width,e.height);a.drawImage(e,0,0);usejpeg||"jpg"==d||"jpeg"==d?(1=this.html.length}; PDFHtmlParser.prototype.getCurrentChar=function(){return this.ant};PDFHtmlParser.prototype.nextText=function(){if(this.last())return!1;this.pos=this.html.indexOf("<",this.ant);-1==this.pos&&(this.pos=this.html.length);var a=this.originalHtml.substring(this.ant,this.pos);this.ant=this.pos;return a=NormalizeTextStringToPDFString(a)};PDFHtmlParser.prototype.getAttrib=function(a,b){var c=a.indexOf(b+'="');if(-1!=c){var c=c+(b.length+2),d=a.indexOf('"',c);-1==d&&(d=a.length);return a.substring(c,d)}return!1}; PDFHtmlParser.prototype.nextTag=function(a){if(this.last())return!1;if(""==this.html.substr(this.pos,3))this.pos+=3,this.textState.bold=!0,this.textState.font=void 0;else if(""==this.html.substr(this.pos,4))this.pos+=4,this.textState.bold=!1,this.textState.font=void 0;else if(""==this.html.substr(this.pos,3))this.pos+=3,this.textState.italic=!0,this.textState.font=void 0;else if(""==this.html.substr(this.pos,4))this.pos+=4,this.textState.italic=!1,this.textState.font=void 0;else if(""== this.html.substr(this.pos,3))this.pos+=3,this.textState.underline=!0;else if(""==this.html.substr(this.pos,4))this.pos+=4,this.textState.underline=!1;else if(""==this.html.substr(this.pos,3))this.pos+=3,this.textState.strike=!0;else if(""==this.html.substr(this.pos,4))this.pos+=4,this.textState.strike=!1;else if("",this.pos);-1==b&&(b=this.html.length);a=this.html.substring(this.pos+ 5,b);var c=this.getAttrib(a,"face");c&&this.textState.fontSetName(c);if(c=this.getAttrib(a,"size"))this.textState.fontSize=parseInt(c);if(a=this.getAttrib(a,"color"))this.textState.color=new PDFColor(a);this.pos=b+1}else if(""==this.html.substr(this.pos,7))this.pos+=7,this.textState.copyFrom(this.states.pop());else if("",this.pos);-1!=b&&"/"==this.html.substr(b-1,1)||this.states.push(this.textState.clone());-1==b&&(b=this.html.length); var c=this.html.substring(this.pos+3,b),d=this.getAttrib(c,"name");d&&this.pdf.addAnchor(d,this.pdf.private_currentPage.pageNumber,a.topY);if(a=this.getAttrib(c,"href"))this.textState.link=a;this.pos=b+1}else if(""==this.html.substr(this.pos,4))this.pos+=4,this.textState.copyFrom(this.states.pop());else throw"html parser ERROR: unkown tag "+this.html.substr(this.pos,5)+"...";this.ant=this.pos;return!0}; function PDFTextState(){this.fontName="Helvetica";this.fontSize=12;this.strike=this.underline=this.italic=this.bold=!1;this.color=new PDFColor(0,0,0);this.link=this.font=void 0;this.linkColor=new PDFColor(0,0,255);this.linkUnderline=!0;this.alpha=1}PDFTextState.prototype.fontSetName=function(a){if(null!=PDFFont.getPDFName(a,this.bold,this.italic))this.fontName=a,this.font=void 0;else throw"The font ["+a+"] is not supported.";};PDFTextState.prototype.fontSetSize=function(a){this.fontSize=a}; PDFTextState.prototype.fontSetStyle=function(a,b,c){this.bold=a;this.italic=b;this.underline=c;this.font=void 0};PDFTextState.prototype.fontSetStyle=function(a,b,c,d){this.bold=a;this.italic=b;this.underline=c;this.strike=d;this.font=void 0};PDFTextState.prototype.setColor=function(a){this.color=a};PDFTextState.prototype.setAlpha=function(a){this.alpha=a};PDFTextState.prototype.getFontName=function(){return PDFFont.getPDFName(this.fontName,this.bold,this.italic)}; PDFTextState.prototype.setFont=function(a){this.font=a};PDFTextState.prototype.setLinkStyle=function(a,b){this.linkUnderline=a;this.linkColor=b};PDFTextState.prototype.clone=function(){var a=new PDFTextState;a.fontName=this.fontName;a.fontSize=this.fontSize;a.bold=this.bold;a.italic=this.italic;a.underline=this.underline;a.strike=this.strike;a.color=this.color;a.alpha=this.alpha;a.font=this.font;a.link=this.link;a.linkColor=this.linkColor;a.linkUnderline=this.linkUnderline;return a}; PDFTextState.prototype.copyFrom=function(a){this.fontName=a.fontName;this.fontSize=a.fontSize;this.bold=a.bold;this.italic=a.italic;this.underline=a.underline;this.strike=a.strike;this.color=a.color;this.alpha=a.alpha;this.font=a.font;this.link=a.link;this.linkColor=a.linkColor;this.linkUnderline=a.linkUnderline};