12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943 |
- var jsPDF = (function () {
- 'use strict';
-
-
- if (typeof btoa === 'undefined') {
- window.btoa = function (data) {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
- b64a = b64.split(''),
- o1,
- o2,
- o3,
- h1,
- h2,
- h3,
- h4,
- bits,
- i = 0,
- ac = 0,
- enc = "",
- tmp_arr = [],
- r;
- do {
- o1 = data.charCodeAt(i++);
- o2 = data.charCodeAt(i++);
- o3 = data.charCodeAt(i++);
- bits = o1 << 16 | o2 << 8 | o3;
- h1 = bits >> 18 & 0x3f;
- h2 = bits >> 12 & 0x3f;
- h3 = bits >> 6 & 0x3f;
- h4 = bits & 0x3f;
-
- tmp_arr[ac++] = b64a[h1] + b64a[h2] + b64a[h3] + b64a[h4];
- } while (i < data.length);
- enc = tmp_arr.join('');
- r = data.length % 3;
- return (r ? enc.slice(0, r - 3) : enc) + '==='.slice(r || 3);
-
- };
- }
- if (typeof atob === 'undefined') {
- window.atob = function (data) {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
- o1,
- o2,
- o3,
- h1,
- h2,
- h3,
- h4,
- bits,
- i = 0,
- ac = 0,
- dec = "",
- tmp_arr = [];
- if (!data) {
- return data;
- }
- data += '';
- do {
- h1 = b64.indexOf(data.charAt(i++));
- h2 = b64.indexOf(data.charAt(i++));
- h3 = b64.indexOf(data.charAt(i++));
- h4 = b64.indexOf(data.charAt(i++));
- bits = h1 << 18 | h2 << 12 | h3 << 6 | h4;
- o1 = bits >> 16 & 0xff;
- o2 = bits >> 8 & 0xff;
- o3 = bits & 0xff;
- if (h3 === 64) {
- tmp_arr[ac++] = String.fromCharCode(o1);
- } else if (h4 === 64) {
- tmp_arr[ac++] = String.fromCharCode(o1, o2);
- } else {
- tmp_arr[ac++] = String.fromCharCode(o1, o2, o3);
- }
- } while (i < data.length);
- dec = tmp_arr.join('');
- return dec;
- };
- }
- var getObjectLength = typeof Object.keys === 'function' ?
- function (object) {
- return Object.keys(object).length;
- } :
- function (object) {
- var i = 0, e;
- for (e in object) {
- if (object.hasOwnProperty(e)) {
- i++;
- }
- }
- return i;
- },
- PubSub = function (context) {
-
-
- this.topics = {};
-
- this.context = context;
-
- this.publish = function (topic, args) {
- if (this.topics[topic]) {
- var currentTopic = this.topics[topic],
- toremove = [],
- fn,
- i,
- l,
- pair,
- emptyFunc = function () {};
- args = Array.prototype.slice.call(arguments, 1);
- for (i = 0, l = currentTopic.length; i < l; i++) {
- pair = currentTopic[i];
- fn = pair[0];
- if (pair[1]) {
- pair[0] = emptyFunc;
- toremove.push(i);
- }
- fn.apply(this.context, args);
- }
- for (i = 0, l = toremove.length; i < l; i++) {
- currentTopic.splice(toremove[i], 1);
- }
- }
- };
-
- this.subscribe = function (topic, callback, once) {
- if (!this.topics[topic]) {
- this.topics[topic] = [[callback, once]];
- } else {
- this.topics[topic].push([callback, once]);
- }
- return {
- "topic": topic,
- "callback": callback
- };
- };
-
- this.unsubscribe = function (token) {
- if (this.topics[token.topic]) {
- var currentTopic = this.topics[token.topic], i, l;
- for (i = 0, l = currentTopic.length; i < l; i++) {
- if (currentTopic[i][0] === token.callback) {
- currentTopic.splice(i, 1);
- }
- }
- }
- };
- };
- function jsPDF(orientation, unit, format, compressPdf) {
-
- if (typeof orientation === 'undefined') {
- orientation = 'p';
- } else {
- orientation = orientation.toString().toLowerCase();
- }
- if (typeof unit === 'undefined') { unit = 'mm'; }
- if (typeof format === 'undefined') { format = 'a4'; }
- if (typeof compressPdf === 'undefined' && typeof zpipe === 'undefined') { compressPdf = false; }
- var format_as_string = format.toString().toLowerCase(),
- version = '0.9.0rc2',
- content = [],
- content_length = 0,
- compress = compressPdf,
- pdfVersion = '1.3',
- pageFormats = {
- 'a0': [2383.94, 3370.39],
- 'a1': [1683.78, 2383.94],
- 'a2': [1190.55, 1683.78],
- 'a3': [841.89, 1190.55],
- 'a4': [595.28, 841.89],
- 'a5': [419.53, 595.28],
- 'a6': [297.64, 419.53],
- 'a7': [209.76, 297.64],
- 'a8': [147.4 , 209.76],
- 'a9': [104.88, 147.4],
- 'a10': [73.7, 104.88],
- 'b0': [2834.65, 4008.19],
- 'b1': [2004.09, 2834.65],
- 'b2': [1417.32, 2004.09],
- 'b3': [1000.63, 1417.32],
- 'b4': [708.66, 1000.63],
- 'b5': [498.9, 708.66],
- 'b6': [354.33, 498.9],
- 'b7': [249.45, 354.33],
- 'b8': [175.75, 249.45],
- 'b9': [124.72, 175.75],
- 'b10': [87.87, 124.72],
- 'c0': [2599.37, 3676.54],
- 'c1': [1836.85, 2599.37],
- 'c2': [1298.27, 1836.85],
- 'c3': [918.43, 1298.27],
- 'c4': [649.13, 918.43],
- 'c5': [459.21, 649.13],
- 'c6': [323.15, 459.21],
- 'c7': [229.61, 323.15],
- 'c8': [161.57, 229.61],
- 'c9': [113.39, 161.57],
- 'c10': [79.37, 113.39],
- 'letter': [612, 792],
- 'government-letter': [576, 756],
- 'legal': [612, 1008],
- 'junior-legal': [576, 360],
- 'ledger': [1224, 792],
- 'tabloid': [792, 1224]
- },
- textColor = '0 g',
- drawColor = '0 G',
- page = 0,
- pages = [],
- objectNumber = 2,
- outToPages = false,
- offsets = [],
- fonts = {},
- fontmap = {},
- activeFontSize = 16,
- activeFontKey,
- lineWidth = 0.200025,
- lineHeightProportion = 1.15,
- pageHeight,
- pageWidth,
- k,
- documentProperties = {'title': '', 'subject': '', 'author': '', 'keywords': '', 'creator': ''},
- lineCapID = 0,
- lineJoinID = 0,
- API = {},
- events = new PubSub(API),
- tmp,
- plugin,
-
-
-
-
- f2 = function (number) {
- return number.toFixed(2);
- },
-
- f3 = function (number) {
- return number.toFixed(3);
- },
-
- padd2 = function (number) {
- var n = (number).toFixed(0);
- if (number < 10) {
- return '0' + n;
- } else {
- return n;
- }
- },
-
- padd10 = function (number) {
- var n = (number).toFixed(0);
- if (n.length < 10) {
- return new Array( 11 - n.length ).join('0') + n;
- } else {
- return n;
- }
- },
- out = function (string) {
- if (outToPages) {
- pages[page].push(string);
- } else {
- content.push(string);
- content_length += string.length + 1;
- }
- },
- newObject = function () {
-
- objectNumber++;
- offsets[objectNumber] = content_length;
- out(objectNumber + ' 0 obj');
- return objectNumber;
- },
- putStream = function (str) {
- out('stream');
- out(str);
- out('endstream');
- },
- wPt,
- hPt,
- kids,
- i,
- putPages = function () {
- wPt = pageWidth * k;
- hPt = pageHeight * k;
-
- var n, p, arr, uint, i, deflater, adler32;
- for (n = 1; n <= page; n++) {
- newObject();
- out('<</Type /Page');
- out('/Parent 1 0 R');
- out('/Resources 2 0 R');
- out('/Contents ' + (objectNumber + 1) + ' 0 R>>');
- out('endobj');
-
- p = pages[n].join('\n');
- newObject();
- if (compress) {
- arr = [];
- for (i = 0; i < p.length; ++i) {
- arr[i] = p.charCodeAt(i);
- }
- adler32 = adler32cs.from(p);
- deflater = new Deflater(6);
- deflater.append(new Uint8Array(arr));
- p = deflater.flush();
- arr = [new Uint8Array([120, 156]), new Uint8Array(p),
- new Uint8Array([adler32 & 0xFF, (adler32 >> 8) & 0xFF, (adler32 >> 16) & 0xFF, (adler32 >> 24) & 0xFF])];
- p = '';
- for (i in arr) {
- if (arr.hasOwnProperty(i)) {
- p += String.fromCharCode.apply(null, arr[i]);
- }
- }
- out('<</Length ' + p.length + ' /Filter [/FlateDecode]>>');
- } else {
- out('<</Length ' + p.length + '>>');
- }
- putStream(p);
- out('endobj');
- }
- offsets[1] = content_length;
- out('1 0 obj');
- out('<</Type /Pages');
- kids = '/Kids [';
- for (i = 0; i < page; i++) {
- kids += (3 + 2 * i) + ' 0 R ';
- }
- out(kids + ']');
- out('/Count ' + page);
- out('/MediaBox [0 0 ' + f2(wPt) + ' ' + f2(hPt) + ']');
- out('>>');
- out('endobj');
- },
- putFont = function (font) {
- font.objectNumber = newObject();
- out('<</BaseFont/' + font.PostScriptName + '/Type/Font');
- if (typeof font.encoding === 'string') {
- out('/Encoding/' + font.encoding);
- }
- out('/Subtype/Type1>>');
- out('endobj');
- },
- putFonts = function () {
- var fontKey;
- for (fontKey in fonts) {
- if (fonts.hasOwnProperty(fontKey)) {
- putFont(fonts[fontKey]);
- }
- }
- },
- putXobjectDict = function () {
-
- events.publish('putXobjectDict');
- },
- putResourceDictionary = function () {
- out('/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]');
- out('/Font <<');
-
- var fontKey;
- for (fontKey in fonts) {
- if (fonts.hasOwnProperty(fontKey)) {
- out('/' + fontKey + ' ' + fonts[fontKey].objectNumber + ' 0 R');
- }
- }
- out('>>');
- out('/XObject <<');
- putXobjectDict();
- out('>>');
- },
- putResources = function () {
- putFonts();
- events.publish('putResources');
-
- offsets[2] = content_length;
- out('2 0 obj');
- out('<<');
- putResourceDictionary();
- out('>>');
- out('endobj');
- events.publish('postPutResources');
- },
- addToFontDictionary = function (fontKey, fontName, fontStyle) {
-
-
- var undef;
- if (fontmap[fontName] === undef) {
- fontmap[fontName] = {};
- }
- fontmap[fontName][fontStyle] = fontKey;
- },
-
- FontObject = {},
- addFont = function (PostScriptName, fontName, fontStyle, encoding) {
- var fontKey = 'F' + (getObjectLength(fonts) + 1).toString(10),
-
- font = fonts[fontKey] = {
- 'id': fontKey,
-
- 'PostScriptName': PostScriptName,
- 'fontName': fontName,
- 'fontStyle': fontStyle,
- 'encoding': encoding,
- 'metadata': {}
- };
- addToFontDictionary(fontKey, fontName, fontStyle);
- events.publish('addFont', font);
- return fontKey;
- },
- addFonts = function () {
- var HELVETICA = "helvetica",
- TIMES = "times",
- COURIER = "courier",
- NORMAL = "normal",
- BOLD = "bold",
- ITALIC = "italic",
- BOLD_ITALIC = "bolditalic",
- encoding = 'StandardEncoding',
- standardFonts = [
- ['Helvetica', HELVETICA, NORMAL],
- ['Helvetica-Bold', HELVETICA, BOLD],
- ['Helvetica-Oblique', HELVETICA, ITALIC],
- ['Helvetica-BoldOblique', HELVETICA, BOLD_ITALIC],
- ['Courier', COURIER, NORMAL],
- ['Courier-Bold', COURIER, BOLD],
- ['Courier-Oblique', COURIER, ITALIC],
- ['Courier-BoldOblique', COURIER, BOLD_ITALIC],
- ['Times-Roman', TIMES, NORMAL],
- ['Times-Bold', TIMES, BOLD],
- ['Times-Italic', TIMES, ITALIC],
- ['Times-BoldItalic', TIMES, BOLD_ITALIC]
- ],
- i,
- l,
- fontKey,
- parts;
- for (i = 0, l = standardFonts.length; i < l; i++) {
- fontKey = addFont(
- standardFonts[i][0],
- standardFonts[i][1],
- standardFonts[i][2],
- encoding
- );
-
- parts = standardFonts[i][0].split('-');
- addToFontDictionary(fontKey, parts[0], parts[1] || '');
- }
- events.publish('addFonts', {'fonts': fonts, 'dictionary': fontmap});
- },
-
- to8bitStream = function (text, flags) {
-
-
- var i, l, undef, sourceEncoding, encodingBlock, outputEncoding, newtext, isUnicode, ch, bch;
- if (flags === undef) {
- flags = {};
- }
- sourceEncoding = flags.sourceEncoding ? sourceEncoding : 'Unicode';
- outputEncoding = flags.outputEncoding;
-
-
-
-
-
-
-
-
-
- if ((flags.autoencode || outputEncoding) &&
- fonts[activeFontKey].metadata &&
- fonts[activeFontKey].metadata[sourceEncoding] &&
- fonts[activeFontKey].metadata[sourceEncoding].encoding
- ) {
- encodingBlock = fonts[activeFontKey].metadata[sourceEncoding].encoding;
-
- if (!outputEncoding && fonts[activeFontKey].encoding) {
- outputEncoding = fonts[activeFontKey].encoding;
- }
-
- if (!outputEncoding && encodingBlock.codePages) {
- outputEncoding = encodingBlock.codePages[0];
- }
- if (typeof outputEncoding === 'string') {
- outputEncoding = encodingBlock[outputEncoding];
- }
-
-
-
- if (outputEncoding) {
- isUnicode = false;
- newtext = [];
- for (i = 0, l = text.length; i < l; i++) {
- ch = outputEncoding[text.charCodeAt(i)];
- if (ch) {
- newtext.push(
- String.fromCharCode(ch)
- );
- } else {
- newtext.push(
- text[i]
- );
- }
-
-
- if (newtext[i].charCodeAt(0) >> 8) {
- isUnicode = true;
- }
- }
- text = newtext.join('');
- }
- }
- i = text.length;
-
- while (isUnicode === undef && i !== 0) {
- if (text.charCodeAt(i - 1) >> 8) {
- isUnicode = true;
- }
- i--;
- }
- if (!isUnicode) {
- return text;
- } else {
- newtext = flags.noBOM ? [] : [254, 255];
- for (i = 0, l = text.length; i < l; i++) {
- ch = text.charCodeAt(i);
- bch = ch >> 8;
- if (bch >> 8) {
- throw new Error("Character at position " + i.toString(10) + " of string '" + text + "' exceeds 16bits. Cannot be encoded into UCS-2 BE");
- }
- newtext.push(bch);
- newtext.push(ch - (bch << 8));
- }
- return String.fromCharCode.apply(undef, newtext);
- }
- },
-
- pdfEscape = function (text, flags) {
-
-
-
-
-
-
-
-
- return to8bitStream(text, flags).replace(/\\/g, '\\\\').replace(/\(/g, '\\(').replace(/\)/g, '\\)');
- },
- putInfo = function () {
- out('/Producer (jsPDF ' + version + ')');
- if (documentProperties.title) {
- out('/Title (' + pdfEscape(documentProperties.title) + ')');
- }
- if (documentProperties.subject) {
- out('/Subject (' + pdfEscape(documentProperties.subject) + ')');
- }
- if (documentProperties.author) {
- out('/Author (' + pdfEscape(documentProperties.author) + ')');
- }
- if (documentProperties.keywords) {
- out('/Keywords (' + pdfEscape(documentProperties.keywords) + ')');
- }
- if (documentProperties.creator) {
- out('/Creator (' + pdfEscape(documentProperties.creator) + ')');
- }
- var created = new Date();
- out('/CreationDate (D:' +
- [
- created.getFullYear(),
- padd2(created.getMonth() + 1),
- padd2(created.getDate()),
- padd2(created.getHours()),
- padd2(created.getMinutes()),
- padd2(created.getSeconds())
- ].join('') +
- ')'
- );
- },
- putCatalog = function () {
- out('/Type /Catalog');
- out('/Pages 1 0 R');
-
- out('/OpenAction [3 0 R /FitH null]');
- out('/PageLayout /OneColumn');
- events.publish('putCatalog');
- },
- putTrailer = function () {
- out('/Size ' + (objectNumber + 1));
- out('/Root ' + objectNumber + ' 0 R');
- out('/Info ' + (objectNumber - 1) + ' 0 R');
- },
- beginPage = function () {
- page++;
-
- outToPages = true;
- pages[page] = [];
- },
- _addPage = function () {
- beginPage();
-
- out(f2(lineWidth * k) + ' w');
-
- out(drawColor);
-
- if (lineCapID !== 0) {
- out(lineCapID.toString(10) + ' J');
- }
- if (lineJoinID !== 0) {
- out(lineJoinID.toString(10) + ' j');
- }
- events.publish('addPage', {'pageNumber': page});
- },
-
- getFont = function (fontName, fontStyle) {
- var key, undef;
- if (fontName === undef) {
- fontName = fonts[activeFontKey].fontName;
- }
- if (fontStyle === undef) {
- fontStyle = fonts[activeFontKey].fontStyle;
- }
- try {
- key = fontmap[fontName][fontStyle];
- } catch (e) {
- key = undef;
- }
- if (!key) {
- throw new Error("Unable to look up font label for font '" + fontName + "', '" + fontStyle + "'. Refer to getFontList() for available fonts.");
- }
- return key;
- },
- buildDocument = function () {
- outToPages = false;
- content = [];
- offsets = [];
-
- out('%PDF-' + pdfVersion);
- putPages();
- putResources();
-
- newObject();
- out('<<');
- putInfo();
- out('>>');
- out('endobj');
-
- newObject();
- out('<<');
- putCatalog();
- out('>>');
- out('endobj');
-
- var o = content_length, i;
- out('xref');
- out('0 ' + (objectNumber + 1));
- out('0000000000 65535 f ');
- for (i = 1; i <= objectNumber; i++) {
- out(padd10(offsets[i]) + ' 00000 n ');
- }
-
- out('trailer');
- out('<<');
- putTrailer();
- out('>>');
- out('startxref');
- out(o);
- out('%%EOF');
- outToPages = true;
- return content.join('\n');
- },
- getStyle = function (style) {
-
- var op = 'S';
- if (style === 'F') {
- op = 'f';
- } else if (style === 'FD' || style === 'DF') {
- op = 'B';
- }
- return op;
- },
-
- output = function (type, options) {
- var undef, data, length, array, i, blob;
- switch (type) {
- case undef:
- return buildDocument();
- case 'save':
- if (navigator.getUserMedia) {
- if (window.URL === undefined) {
- return API.output('dataurlnewwindow');
- } else if (window.URL.createObjectURL === undefined) {
- return API.output('dataurlnewwindow');
- }
- }
- data = buildDocument();
-
- length = data.length;
- array = new Uint8Array(new ArrayBuffer(length));
- for (i = 0; i < length; i++) {
- array[i] = data.charCodeAt(i);
- }
- blob = new Blob([array], {type: "application/pdf"});
- saveAs(blob, options);
- break;
- case 'datauristring':
- case 'dataurlstring':
- return 'data:application/pdf;base64,' + btoa(buildDocument());
- case 'datauri':
- case 'dataurl':
- document.location.href = 'data:application/pdf;base64,' + btoa(buildDocument());
- break;
- case 'dataurlnewwindow':
- window.open('data:application/pdf;base64,' + btoa(buildDocument()));
- break;
- default:
- throw new Error('Output type "' + type + '" is not supported.');
- }
-
- };
- if (unit === 'pt') {
- k = 1;
- } else if (unit === 'mm') {
- k = 72 / 25.4;
- } else if (unit === 'cm') {
- k = 72 / 2.54;
- } else if (unit === 'in') {
- k = 72;
- } else {
- throw ('Invalid unit: ' + unit);
- }
-
- if (pageFormats.hasOwnProperty(format_as_string)) {
- pageHeight = pageFormats[format_as_string][1] / k;
- pageWidth = pageFormats[format_as_string][0] / k;
- } else {
- try {
- pageHeight = format[1];
- pageWidth = format[0];
- } catch (err) {
- throw ('Invalid format: ' + format);
- }
- }
- if (orientation === 'p' || orientation === 'portrait') {
- orientation = 'p';
- if (pageWidth > pageHeight) {
- tmp = pageWidth;
- pageWidth = pageHeight;
- pageHeight = tmp;
- }
- } else if (orientation === 'l' || orientation === 'landscape') {
- orientation = 'l';
- if (pageHeight > pageWidth) {
- tmp = pageWidth;
- pageWidth = pageHeight;
- pageHeight = tmp;
- }
- } else {
- throw ('Invalid orientation: ' + orientation);
- }
-
-
-
- API.internal = {
- 'pdfEscape': pdfEscape,
- 'getStyle': getStyle,
-
- 'getFont': function () { return fonts[getFont.apply(API, arguments)]; },
- 'getFontSize': function () { return activeFontSize; },
- 'getLineHeight': function () { return activeFontSize * lineHeightProportion; },
- 'btoa': btoa,
- 'write': function (string1, string2, string3, etc) {
- out(
- arguments.length === 1 ? string1 : Array.prototype.join.call(arguments, ' ')
- );
- },
- 'getCoordinateString': function (value) {
- return f2(value * k);
- },
- 'getVerticalCoordinateString': function (value) {
- return f2((pageHeight - value) * k);
- },
- 'collections': {},
- 'newObject': newObject,
- 'putStream': putStream,
- 'events': events,
-
-
-
-
-
-
- 'scaleFactor': k,
- 'pageSize': {'width': pageWidth, 'height': pageHeight},
- 'output': function (type, options) {
- return output(type, options);
- },
- 'getNumberOfPages': function () {return pages.length - 1; },
- 'pages': pages
- };
-
- API.addPage = function () {
- _addPage();
- return this;
- };
-
- API.text = function (text, x, y, flags) {
-
- var undef, _first, _second, _third, newtext, str, i;
-
-
-
-
-
- if (typeof text === 'number') {
- _first = y;
- _second = text;
- _third = x;
- text = _first;
- x = _second;
- y = _third;
- }
-
-
-
-
- if (typeof text === 'string' && text.match(/[\n\r]/)) {
- text = text.split(/\r\n|\r|\n/g);
- }
- if (typeof flags === 'undefined') {
- flags = {'noBOM': true, 'autoencode': true};
- } else {
- if (flags.noBOM === undef) {
- flags.noBOM = true;
- }
- if (flags.autoencode === undef) {
- flags.autoencode = true;
- }
- }
- if (typeof text === 'string') {
- str = pdfEscape(text, flags);
- } else if (text instanceof Array) {
-
- newtext = text.concat();
-
-
- for (i = newtext.length - 1; i !== -1; i--) {
- newtext[i] = pdfEscape(newtext[i], flags);
- }
- str = newtext.join(") Tj\nT* (");
- } else {
- throw new Error('Type of text must be string or Array. "' + text + '" is not recognized.');
- }
-
-
-
-
-
-
- out(
- 'BT\n/' +
- activeFontKey + ' ' + activeFontSize + ' Tf\n' +
- (activeFontSize * lineHeightProportion) + ' TL\n' +
- textColor +
- '\n' + f2(x * k) + ' ' + f2((pageHeight - y) * k) + ' Td\n(' +
- str +
- ') Tj\nET'
- );
- return this;
- };
- API.line = function (x1, y1, x2, y2) {
- out(
- f2(x1 * k) + ' ' + f2((pageHeight - y1) * k) + ' m ' +
- f2(x2 * k) + ' ' + f2((pageHeight - y2) * k) + ' l S'
- );
- return this;
- };
-
- API.lines = function (lines, x, y, scale, style, closed) {
- var undef, _first, _second, _third, scalex, scaley, i, l, leg, x2, y2, x3, y3, x4, y4;
-
-
-
-
-
- if (typeof lines === 'number') {
- _first = y;
- _second = lines;
- _third = x;
- lines = _first;
- x = _second;
- y = _third;
- }
- style = getStyle(style);
- scale = scale === undef ? [1, 1] : scale;
-
- out(f3(x * k) + ' ' + f3((pageHeight - y) * k) + ' m ');
- scalex = scale[0];
- scaley = scale[1];
- l = lines.length;
-
-
-
- x4 = x;
- y4 = y;
- for (i = 0; i < l; i++) {
- leg = lines[i];
- if (leg.length === 2) {
-
- x4 = leg[0] * scalex + x4;
- y4 = leg[1] * scaley + y4;
- out(f3(x4 * k) + ' ' + f3((pageHeight - y4) * k) + ' l');
- } else {
-
- x2 = leg[0] * scalex + x4;
- y2 = leg[1] * scaley + y4;
- x3 = leg[2] * scalex + x4;
- y3 = leg[3] * scaley + y4;
- x4 = leg[4] * scalex + x4;
- y4 = leg[5] * scaley + y4;
- out(
- f3(x2 * k) + ' ' +
- f3((pageHeight - y2) * k) + ' ' +
- f3(x3 * k) + ' ' +
- f3((pageHeight - y3) * k) + ' ' +
- f3(x4 * k) + ' ' +
- f3((pageHeight - y4) * k) + ' c'
- );
- }
- }
- if (closed == true) {
- out(' h');
- }
-
- out(style);
- return this;
- };
-
- API.rect = function (x, y, w, h, style) {
- var op = getStyle(style);
- out([
- f2(x * k),
- f2((pageHeight - y) * k),
- f2(w * k),
- f2(-h * k),
- 're',
- op
- ].join(' '));
- return this;
- };
-
- API.triangle = function (x1, y1, x2, y2, x3, y3, style) {
- this.lines(
- [
- [ x2 - x1, y2 - y1 ],
- [ x3 - x2, y3 - y2 ],
- [ x1 - x3, y1 - y3 ]
- ],
- x1,
- y1,
- [1, 1],
- style,
- true
- );
- return this;
- };
-
- API.roundedRect = function (x, y, w, h, rx, ry, style) {
- var MyArc = 4 / 3 * (Math.SQRT2 - 1);
- this.lines(
- [
- [ (w - 2 * rx), 0 ],
- [ (rx * MyArc), 0, rx, ry - (ry * MyArc), rx, ry ],
- [ 0, (h - 2 * ry) ],
- [ 0, (ry * MyArc), -(rx * MyArc), ry, -rx, ry],
- [ (-w + 2 * rx), 0],
- [ -(rx * MyArc), 0, -rx, -(ry * MyArc), -rx, -ry],
- [ 0, (-h + 2 * ry)],
- [ 0, -(ry * MyArc), (rx * MyArc), -ry, rx, -ry]
- ],
- x + rx,
- y,
- [1, 1],
- style
- );
- return this;
- };
-
- API.ellipse = function (x, y, rx, ry, style) {
- var op = getStyle(style),
- lx = 4 / 3 * (Math.SQRT2 - 1) * rx,
- ly = 4 / 3 * (Math.SQRT2 - 1) * ry;
- out([
- f2((x + rx) * k),
- f2((pageHeight - y) * k),
- 'm',
- f2((x + rx) * k),
- f2((pageHeight - (y - ly)) * k),
- f2((x + lx) * k),
- f2((pageHeight - (y - ry)) * k),
- f2(x * k),
- f2((pageHeight - (y - ry)) * k),
- 'c'
- ].join(' '));
- out([
- f2((x - lx) * k),
- f2((pageHeight - (y - ry)) * k),
- f2((x - rx) * k),
- f2((pageHeight - (y - ly)) * k),
- f2((x - rx) * k),
- f2((pageHeight - y) * k),
- 'c'
- ].join(' '));
- out([
- f2((x - rx) * k),
- f2((pageHeight - (y + ly)) * k),
- f2((x - lx) * k),
- f2((pageHeight - (y + ry)) * k),
- f2(x * k),
- f2((pageHeight - (y + ry)) * k),
- 'c'
- ].join(' '));
- out([
- f2((x + lx) * k),
- f2((pageHeight - (y + ry)) * k),
- f2((x + rx) * k),
- f2((pageHeight - (y + ly)) * k),
- f2((x + rx) * k),
- f2((pageHeight - y) * k),
- 'c',
- op
- ].join(' '));
- return this;
- };
-
- API.circle = function (x, y, r, style) {
- return this.ellipse(x, y, r, r, style);
- };
-
- API.setProperties = function (properties) {
-
- var property;
- for (property in documentProperties) {
- if (documentProperties.hasOwnProperty(property) && properties[property]) {
- documentProperties[property] = properties[property];
- }
- }
- return this;
- };
-
- API.setFontSize = function (size) {
- activeFontSize = size;
- return this;
- };
-
- API.setFont = function (fontName, fontStyle) {
- activeFontKey = getFont(fontName, fontStyle);
-
- return this;
- };
-
- API.setFontStyle = API.setFontType = function (style) {
- var undef;
- activeFontKey = getFont(undef, style);
-
- return this;
- };
-
- API.getFontList = function () {
-
- var list = {},
- fontName,
- fontStyle,
- tmp;
- for (fontName in fontmap) {
- if (fontmap.hasOwnProperty(fontName)) {
- list[fontName] = tmp = [];
- for (fontStyle in fontmap[fontName]) {
- if (fontmap[fontName].hasOwnProperty(fontStyle)) {
- tmp.push(fontStyle);
- }
- }
- }
- }
- return list;
- };
-
- API.setLineWidth = function (width) {
- out((width * k).toFixed(2) + ' w');
- return this;
- };
-
- API.setDrawColor = function (ch1, ch2, ch3, ch4) {
- var color;
- if (ch2 === undefined || (ch4 === undefined && ch1 === ch2 === ch3)) {
-
- if (typeof ch1 === 'string') {
- color = ch1 + ' G';
- } else {
- color = f2(ch1 / 255) + ' G';
- }
- } else if (ch4 === undefined) {
-
- if (typeof ch1 === 'string') {
- color = [ch1, ch2, ch3, 'RG'].join(' ');
- } else {
- color = [f2(ch1 / 255), f2(ch2 / 255), f2(ch3 / 255), 'RG'].join(' ');
- }
- } else {
-
- if (typeof ch1 === 'string') {
- color = [ch1, ch2, ch3, ch4, 'K'].join(' ');
- } else {
- color = [f2(ch1), f2(ch2), f2(ch3), f2(ch4), 'K'].join(' ');
- }
- }
- out(color);
- return this;
- };
-
- API.setFillColor = function (ch1, ch2, ch3, ch4) {
- var color;
- if (ch2 === undefined || (ch4 === undefined && ch1 === ch2 === ch3)) {
-
- if (typeof ch1 === 'string') {
- color = ch1 + ' g';
- } else {
- color = f2(ch1 / 255) + ' g';
- }
- } else if (ch4 === undefined) {
-
- if (typeof ch1 === 'string') {
- color = [ch1, ch2, ch3, 'rg'].join(' ');
- } else {
- color = [f2(ch1 / 255), f2(ch2 / 255), f2(ch3 / 255), 'rg'].join(' ');
- }
- } else {
-
- if (typeof ch1 === 'string') {
- color = [ch1, ch2, ch3, ch4, 'k'].join(' ');
- } else {
- color = [f2(ch1), f2(ch2), f2(ch3), f2(ch4), 'k'].join(' ');
- }
- }
- out(color);
- return this;
- };
-
- API.setTextColor = function (r, g, b) {
- var patt = /#[0-9A-Fa-f]{6}/;
- if ((typeof r == 'string') && patt.test(r)) {
- var hex = r.replace('#','');
- var bigint = parseInt(hex, 16);
- r = (bigint >> 16) & 255;
- g = (bigint >> 8) & 255;
- b = bigint & 255;
- }
- if ((r === 0 && g === 0 && b === 0) || (typeof g === 'undefined')) {
- textColor = f3(r / 255) + ' g';
- } else {
- textColor = [f3(r / 255), f3(g / 255), f3(b / 255), 'rg'].join(' ');
- }
- return this;
- };
-
- API.CapJoinStyles = {
- 0: 0,
- 'butt': 0,
- 'but': 0,
- 'miter': 0,
- 1: 1,
- 'round': 1,
- 'rounded': 1,
- 'circle': 1,
- 2: 2,
- 'projecting': 2,
- 'project': 2,
- 'square': 2,
- 'bevel': 2
- };
-
- API.setLineCap = function (style) {
- var id = this.CapJoinStyles[style];
- if (id === undefined) {
- throw new Error("Line cap style of '" + style + "' is not recognized. See or extend .CapJoinStyles property for valid styles");
- }
- lineCapID = id;
- out(id.toString(10) + ' J');
- return this;
- };
-
- API.setLineJoin = function (style) {
- var id = this.CapJoinStyles[style];
- if (id === undefined) {
- throw new Error("Line join style of '" + style + "' is not recognized. See or extend .CapJoinStyles property for valid styles");
- }
- lineJoinID = id;
- out(id.toString(10) + ' j');
- return this;
- };
-
- API.output = output;
-
- API.save = function (filename) {
- API.output('save', filename);
- };
-
-
-
- for (plugin in jsPDF.API) {
- if (jsPDF.API.hasOwnProperty(plugin)) {
- if (plugin === 'events' && jsPDF.API.events.length) {
- (function (events, newEvents) {
-
-
-
-
-
- var eventname, handler_and_args, i;
- for (i = newEvents.length - 1; i !== -1; i--) {
-
-
-
-
-
- eventname = newEvents[i][0];
- handler_and_args = newEvents[i][1];
- events.subscribe.apply(
- events,
- [eventname].concat(
- typeof handler_and_args === 'function' ?
- [ handler_and_args ] :
- handler_and_args
- )
- );
- }
- }(events, jsPDF.API.events));
- } else {
- API[plugin] = jsPDF.API[plugin];
- }
- }
- }
-
-
-
-
- addFonts();
- activeFontKey = 'F1';
- _addPage();
- events.publish('initialized');
- return API;
- }
- jsPDF.API = {'events': []};
- return jsPDF;
- }());
|