UNPKG

pdf2json

Version:

PDF file parser that converts PDF binaries to JSON and text, powered by porting a fork of PDF.JS to Node.js

1 lines 928 kB
"use strict";var e=require("fs"),t=require("util"),a=require("fs/promises"),r=require("events"),i=require("buffer"),n=require("process"),c=require("console"),s=require("@xmldom/xmldom"),o=require("stream"),f="pdf2json",l="3.1.5",h="PDF file parser that converts PDF binaries to JSON and text, powered by porting a fork of PDF.JS to Node.js",u=["pdf","pdf parser","pdf2json","convert pdf to json","convert pdf form to json","server side PDF parser","port pdf.js to node.js","PDF to text","PDF text extractor","PDF binary to text","PDF form extractor","command line utility to parse pdf to json","JSON","javascript","PDF canvas"],d={name:"Modesty Zhang",email:"modestyz@hotmail.com",url:"http://www.codeproject.com/script/Articles/MemberArticles.aspx?amid=62372"},g="https://github.com/modesty/pdf2json",m={type:"git",url:"git://github.com/modesty/pdf2json.git"},p="./dist/pdfparser.cjs",b="./dist/pdfparser.js",v="./pdfparser.d.ts",y={pretest:"npm run build","test:jest":"jest --config ./jest.config.json",test:"jest --config ./jest.config.json && npm run parse-r && npm run parse-fd","test:forms":"cd ./test && sh p2j.forms.sh","test:misc":'cd ./test && sh p2j.one.sh misc . "Expected: 14 success, 5 fail exception with stack trace" ',parse:"./bin/pdf2json.js -f ./test/pdf/fd/form/F1040.pdf -o ./test/target/fd/form","parse-s":"./bin/pdf2json.js -f ./test/pdf/fd/form/F1040.pdf -o ./test/target/fd/form -s","parse-t":"./bin/pdf2json.js -f ./test/pdf/fd/form/F1040.pdf -o ./test/target/fd/form -s -t","parse-c":"./bin/pdf2json.js -f ./test/pdf/fd/form/F1040.pdf -o ./test/target/fd/form -s -t -c","parse-m":"./bin/pdf2json.js -f ./test/pdf/fd/form/F1040.pdf -o ./test/target/fd/form -s -t -c -m","parse-r":"./bin/pdf2json.js -f ./test/pdf/fd/form/F1040.pdf -o ./test/target/fd/form -t -c -m -r","parse-fd":"./bin/pdf2json.js -f ./test/pdf/fd/form/ -o ./test/target/fd/form -t -c -m -r","parse-tb":"./bin/pdf2json.js -f ./test/pdf/misc/i242_testingWithTable.pdf -o ./test/target/misc","parse-tc":"./bin/pdf2json.js -f ./test/pdf/misc/i293_pdfpac.pdf -o ./test/target/misc","parse-rectFix":"./bin/pdf2json.js -f ./test/pdf/misc/pr298_rect_fix_from_upstream.pdf -o ./test/target/misc","parse-e":"./bin/pdf2json.js -f ./test/pdf/misc/i373_err_broken.pdf -o ./test/target/misc","build:rollup":"rollup -c ./rollup.config.js","build:bundle-pdfjs-base":"node rollup/bundle-pdfjs-base.js",build:"npm run build:bundle-pdfjs-base && npm run build:rollup","build:clean":"rm -rf node_modules && rm -f package-lock.json && npm i && npm run build"},k={node:">=20.18.0",npm:">=10.8.2"},A="module",w={pdf2json:"./bin/pdf2json.js"},x={"@xmldom/xmldom":"^0.9.6"},S=["@xmldom/xmldom"],C={"@rollup/plugin-commonjs":"^28.0.2","@rollup/plugin-eslint":"^9.0.5","@rollup/plugin-json":"^6.1.0","@rollup/plugin-node-resolve":"^16.0.0","@rollup/plugin-terser":"^0.4.4","@rollup/plugin-typescript":"^12.1.2","@types/node":"^22.10.2","@typescript-eslint/eslint-plugin":"^8.18.2","@typescript-eslint/parser":"^8.18.2",eslint:"^9.17.0",jest:"^29.7.0",rollup:"^4.29.1","rollup-plugin-node-builtins":"^2.0.0","rollup-plugin-sourcemaps":"^0.6.3",tslib:"^2.6.2"},B={typescript:"5.7.0"},I=[{name:"Modesty Zhang",email:"modestyz@hotmail.com",url:"http://www.codeproject.com/script/Articles/MemberArticles.aspx?amid=62372"}],T=[],L={url:"http://github.com/modesty/pdf2json/issues"},F="Apache-2.0",P="https://github.com/modesty/pdf2json/blob/master/readme.md",R={".":{types:"./dist/pdfparser.d.ts",import:"./dist/pdfparser.js",require:"./dist/pdfparser.cjs"}},O={registry:"https://registry.npmjs.com/",access:"public"},M={name:f,version:l,description:h,keywords:u,author:d,homepage:g,repository:m,main:p,module:b,typings:v,scripts:y,engines:k,type:A,bin:w,dependencies:x,bundleDependencies:S,devDependencies:C,resolutions:B,maintainers:I,contributors:T,bugs:L,license:F,readme:P,exports:R,publishConfig:O},D=Object.freeze({__proto__:null,author:d,bin:w,bugs:L,bundleDependencies:S,contributors:T,default:M,dependencies:x,description:h,devDependencies:C,engines:k,exports:R,homepage:g,keywords:u,license:F,main:p,maintainers:I,module:b,name:f,publishConfig:O,readme:P,repository:m,resolutions:B,scripts:y,type:A,typings:v,version:l});const q=`${f}@${l} [${g}]`,E=["#000000","#ffffff","#4c4c4c","#808080","#999999","#c0c0c0","#cccccc","#e5e5e5","#f2f2f2","#008000","#00ff00","#bfffa0","#ffd629","#ff99cc","#004080","#9fc0e1","#5580ff","#a9c9fa","#ff0080","#800080","#ffbfff","#e45b21","#ffbfaa","#008080","#ff0000","#fdc59f","#808000","#bfbf00","#824100","#007256","#008000","#000080","#008080","#800080","#ff0000","#0000ff","#008000"],N=["quicktype,arial,helvetica,sans-serif","quicktype condensed,arial narrow,arial,helvetica,sans-serif","quicktypepi,quicktypeiipi","quicktype mono,courier new,courier,monospace","ocr-a,courier new,courier,monospace","ocr b mt,courier new,courier,monospace"],j=[[0,6,0,0],[0,8,0,0],[0,10,0,0],[0,12,0,0],[0,14,0,0],[0,18,0,0],[0,6,1,0],[0,8,1,0],[0,10,1,0],[0,12,1,0],[0,14,1,0],[0,18,1,0],[0,6,0,1],[0,8,0,1],[0,10,0,1],[0,12,0,1],[0,14,0,1],[0,18,0,1],[0,6,1,1],[0,8,1,1],[0,10,1,1],[0,12,1,1],[0,14,1,1],[0,18,1,1],[1,6,0,0],[1,8,0,0],[1,10,0,0],[1,12,0,0],[1,14,0,0],[1,18,0,0],[1,6,1,0],[1,8,1,0],[1,10,1,0],[1,12,1,0],[1,14,1,0],[1,18,1,0],[1,6,0,1],[1,8,0,1],[1,10,0,1],[1,12,0,1],[1,14,0,1],[1,18,0,1],[2,8,0,0],[2,10,0,0],[2,12,0,0],[2,14,0,0],[2,18,0,0],[3,8,0,0],[3,10,0,0],[3,12,0,0],[4,12,0,0],[0,9,0,0],[0,9,1,0],[0,9,0,1],[0,9,1,1],[1,9,0,0],[1,9,1,0],[1,9,1,1],[4,10,0,0],[5,10,0,0],[5,12,0,0]],U=96/72;class z{static toFixedFloat(e){return parseFloat(e.toFixed(3))}static colorCount(){return E.length}static toPixelX(e){return Math.round(24*e)}static toPixelY(e){return Math.round(24*e)}static pointToPixel(e){return e*U}static getColorByIndex(e){return E[e]}static toFormPoint(e,t){return[e/24,t/24]}static toFormX(e){return z.toFixedFloat(e/24)}static toFormY(e){return z.toFixedFloat(e/24)}static findColorIndex(e){return 4===e.length&&(e+="000"),E.indexOf(e)}static dateToIso8601(e){"D:"===e.slice(0,2)&&(e=e.slice(2));let t="Z";const a=e.search(/[Z+-]/);a>=0&&(t=e.slice(a),"Z"!==t&&(t=`${t.slice(0,3)}:${t.slice(4,6)}`),e=e.slice(0,a));return`${e.slice(0,4)}-${e.slice(4,6)||"01"}-${e.slice(6,8)||"01"}T${e.slice(8,10)||"00"}:${e.slice(10,12)||"00"}:${e.slice(12,14)||"00"}${t}`}}class H{static tabIndex=0;static isWidgetSupported(e){let a=!1;switch(e.fieldType){case"Tx":case"Ch":case"Sig":a=!0;break;case"Btn":32768&e.fieldFlags?e.fieldType="Rd":65536&e.fieldFlags?e.fieldType="Btn":e.fieldType="Cb",a=!0;break;default:t.p2jwarn(`Unsupported: field.fieldType of ${e.fieldType}`)}return a}static isFormElement(e){let a=!1;if("Widget"===e.subtype)a=H.isWidgetSupported(e);else t.p2jwarn(`Unsupported: field.type of ${e.subtype}`);return a}constructor(e,t,a,r){this.field=e,this.viewport=t,this.Fields=a,this.Boxsets=r}static#e(e){const t=e.slice(0);return e[0]>e[2]&&(t[0]=e[2],t[2]=e[0]),e[1]>e[3]&&(t[1]=e[3],t[3]=e[1]),t}#t(e){const t=this.viewport.convertToViewportRectangle(e.rect),a=H.#e(t);let r=a[3]-a[1];return"Tx"===e.fieldType?r>22&&(a[1]+=2,r-=2):"Ch"!==e.fieldType&&(a[1]-=3),r=r>=20?r:20,{x:z.toFormX(a[0]),y:z.toFormY(a[1]),w:z.toFormX(a[2]-a[0]),h:z.toFormY(r)}}#a(e){let t=0;1&e.fieldFlags&&(t|=1024),2&e.fieldFlags&&(t|=16);const a={id:{Id:e.fullName,EN:0},TI:e.TI,AM:t};return e.alternativeText&&e.alternativeText.length>1&&(a.TU=e.alternativeText),e.alternativeID&&e.alternativeID.length>1&&(a.TM=e.alternativeID),Object.assign(a,this.#t(e))}#r(e){const t=Object.assign({style:48,T:{Name:e.TName||"alpha",TypeInfo:{}}},this.#a(e));e.MV&&(t.MV=e.MV),e.fieldValue&&(t.V=e.fieldValue),this.Fields.push(t)}#i(e){const t=Object.assign({style:48,T:{Name:"box",TypeInfo:{}}},this.#a(e));e.fieldValue&&(t.checked="Off"!==e.fieldValue),this.Boxsets.push({boxes:[t]})}#n(e){const t=Object.assign({style:48,T:{Name:"box",TypeInfo:{}}},this.#a(e));t.id.Id=e.value,"checked"in e&&(t.checked=e.checked);const a=this.Boxsets.filter((t=>"id"in t&&"Id"in t.id&&t.id.Id===e.fullName))[0];a&&"boxes"in a?a.boxes.push(t):this.Boxsets.push({boxes:[t],id:{Id:e.fullName,EN:0}})}#c(e){const t=Object.assign({style:48,T:{Name:"link"},FL:{form:{Id:e.FL}}},this.#a(e));this.Fields.push(t)}#s(e){const t=Object.assign({style:48,T:{Name:"alpha",TypeInfo:{}}},this.#a(e));t.w-=.5,t.PL={V:[],D:[]},e.value.forEach(((e,a)=>{Array.isArray(e)?(t.PL.D.push(e[0]),t.PL.V.push(e[1])):(t.PL.D.push(e),t.PL.V.push(e))})),e.fieldValue&&(t.V=e.fieldValue),this.Fields.push(t)}#o(e){const t=Object.assign({style:48,T:{Name:"signature",TypeInfo:{}}},this.#a(e));e.Sig&&(t.Sig={},e.Sig.Name&&(t.Sig.Name=e.Sig.Name),e.Sig.M&&(t.Sig.M=z.dateToIso8601(e.Sig.M)),e.Sig.Location&&(t.Sig.Location=e.Sig.Location),e.Sig.Reason&&(t.Sig.Reason=e.Sig.Reason),e.Sig.ContactInfo&&(t.Sig.ContactInfo=e.Sig.ContactInfo)),this.Fields.push(t)}processField(){switch(this.field.TI=H.tabIndex++,this.field.fieldType){case"Tx":this.#r(this.field);break;case"Cb":this.#i(this.field);break;case"Rd":this.#n(this.field);break;case"Btn":this.#c(this.field);break;case"Ch":this.#s(this.field);break;case"Sig":this.#o(this.field)}this.clean()}clean(){delete this.field,delete this.viewport,delete this.Fields,delete this.Boxsets}static getAllFieldsTypes(e){const t=e=>!!(1024&e.AM),a=e=>({id:e.id.Id,type:e.T.Name,calc:t(e),value:e.V||""}),r=[];return e.Pages.forEach((e=>{e.Boxsets.forEach((e=>{e.boxes.length>1?e.boxes.forEach((a=>{r.push({id:e.id.Id,type:"radio",calc:t(a),value:a.id.Id})})):r.push(a(e.boxes[0]))})),e.Fields.forEach((e=>r.push(a(e))))})),r}}const G=["bd","bold","demi","black","medi"],_=["arial","helvetica","sans-serif ","courier ","monospace ","ocr "],X=.1;class W{#f(){let e=this.fontObj.name||this.fontObj.fallbackName;return e||(e=N[0]),e=e.toLowerCase(),e}#l(){let e=this.typeName,t=!1;const a=this.typeName.split("+");if(Array.isArray(a)&&a.length>1&&(e=a[1].split("-"),Array.isArray(e)&&e.length>1)){const a=e[1].toLowerCase();t=G.indexOf(a)>=0,e=e[0]}return{subType:e,bold:t}}#h(){const e=this.typeName.indexOf("symbol")>0||N[2].indexOf(this.subType)>=0;if(this.fontObj.isSymbolicFont){_.filter((e=>this.typeName.indexOf(e)>=0)).length>0&&(this.fontObj.isSymbolicFont=!1,t.p2jinfo(`Reset: isSymbolicFont (false) for ${this.fontObj.name}`))}else e&&(this.fontObj.isSymbolicFont=!0,t.p2jinfo(`Reset: isSymbolicFont (true) for ${this.fontObj.name}`));return e}#u(){let{spaceWidth:e}=this.fontObj;if(!e){var t=Array.isArray(this.fontObj.toFontChar)?this.fontObj.toFontChar.indexOf(32):-1;e=t>=0&&Array.isArray(this.fontObj.widths)?this.fontObj.widths[t]:250}return e=z.toFormX(e)/32,e}constructor(e){this.fontObj=e,this.typeName=this.#f();const{subType:t,bold:a}=this.#l();this.subType=t,this.bold=a,this.isSymbol=this.#h(),this.spaceWidth=this.#u(),this.fontSize=1,this.faceIdx=0,this.italic=!1,this.fontStyleId=-1}static compareBlockPos(e,t){if(e.y<t.y-X)return-1;if(Math.abs(e.y-t.y)<=X){if(e.x<t.x-X)return-1;if(Math.abs(e.x-t.x)<=X)return 0}return 1}static haveSameStyle(e,t){let a=e.R[0].S===t.R[0].S;if(a&&e.R[0].S<0)for(let r=0;r<e.R[0].TS.length;r++)if(e.R[0].TS[r]!==t.R[0].TS[r]){a=!1;break}return a&&(a=void 0===e.R[0].RA&&void 0===t.R[0].RA),a}static getSpaceThreshHold(e){return W.getFontSize(e)/12*e.sw}static areAdjacentBlocks(e,t){const a=Math.abs(e.y-t.y)<=X,r=t.x-e.x-e.w<W.getSpaceThreshHold(e);return a&&r}static getFontSize(e){const t=e.R[0].S;return t<0?e.R[0].TS[1]:j[t][1]}static areDuplicateBlocks(e,t){return e.x===t.x&&e.y===t.y&&e.R[0].T===t.R[0].T&&W.haveSameStyle(e,t)}#d(){const{fontObj:e}=this;this.bold=e.bold,this.bold||(this.bold=this.typeName.indexOf("bold")>=0||this.typeName.indexOf("black")>=0),this.italic=e.italic,this.italic||(this.italic=this.typeName.indexOf("italic")>=0||this.typeName.indexOf("oblique")>=0),this.bold&&this.italic||!(this.typeName.indexOf("boldobl")>=0)||(this.bold=!0,this.italic=!0);const t=this.subType;e.isSerifFont?N[1].indexOf(t)>=0&&(this.faceIdx=1):N[2].indexOf(this.subType)>=0?this.faceIdx=2:e.isMonospace?(this.faceIdx=3,N[4].indexOf(t)>=0?this.faceIdx=4:N[5].indexOf(t)>=0&&(this.faceIdx=5)):e.isSymbolicFont&&(this.faceIdx=2),0===this.faceIdx&&this.typeName.indexOf("narrow")>0&&(this.faceIdx=1)}#g(e){this.#d(),this.fontSize=this.bold&&e>12?e+1:e;const t=[this.faceIdx,this.fontSize,this.bold?1:0,this.italic?1:0];let a=-1;return j.forEach(((e,r,i)=>{-1===a&&e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]&&e[3]===t[3]&&(a=r)})),a}#m(e){let a=e;if(!e||1!==e.length)return a;if(!this.fontObj.isSymbolicFont||!this.isSymbol)return"C"!==a&&"G"!==a||(a=` ${a} `),a;switch(e.charCodeAt(0)){case 20:a="✓";break;case 70:a="CIDFontType0"===this.fontObj.type?"⚠":"}";break;case 71:case 97:a="▶";break;case 99:a=this.isSymbol?"•":"▲";break;case 100:a="▼";break;case 103:a="➨";break;case 106:a="";break;case 114:case 116:case 118:a="•";break;case 115:a="▲";break;default:t.p2jinfo(`${this.fontObj.type} - SymbolicFont - (${this.fontObj.name}) : ${e.charCodeAt(0)}::${e.charCodeAt(1)} => ${a}`)}return a}#p(e){let t=0;if(0===e[0][0]&&0===e[1][1])0!==e[0][1]&&0!==e[1][0]&&e[0][1]/e[1][0]+1<1e-4&&(t=90);else if(0!==e[0][0]&&0!==e[1][1]){const a=Math.atan(-e[0][1]/e[0][0]),r=Math.atan(e[1][0]/e[1][1]);Math.abs(a)>1e-4&&a-r<1e-4&&(t=180*a/Math.PI)}return t}processText(e,a,r,i,n,c,s){const o=this.#m(a);if(!o)return;this.fontStyleId=this.#g(n);const f=[this.faceIdx,this.fontSize,this.bold?1:0,this.italic?1:0],l=z.findColorIndex(i),h=l>=0&&l<z.colorCount()?{clr:l}:{oc:i};let u={T:this.flashEncode(o),S:this.fontStyleId,TS:f};const d=this.#p(s);0!==d&&(t.p2jinfo(`${a}: rotated ${d} degree.`),u={...u,RA:d});const g={x:z.toFormX(e.x)-.25,y:z.toFormY(e.y)-.75,w:z.toFixedFloat(r),...h,sw:this.spaceWidth,A:"left",R:[u]};c.Texts.push(g)}flashEncode(e){let t=encodeURIComponent(e);return t=t.replace("%C2%96","-"),t=t.replace("%C2%91","%27"),t=t.replace("%C2%92","%27"),t=t.replace("%C2%82","%27"),t=t.replace("%C2%93","%22"),t=t.replace("%C2%94","%22"),t=t.replace("%C2%84","%22"),t=t.replace("%C2%8B","%C2%AB"),t=t.replace("%C2%9B","%C2%BB"),t}clean(){this.fontObj=null,delete this.fontObj}}class V{xmlData=null;ptiPageArray=[];constructor(){this.xmlData=null,this.ptiPageArray=[]}parseXml(t,a){e.readFile(t,"utf8",((e,t)=>{if(e)a(e);else{this.xmlData=t;for(var r=(new s.DOMParser).parseFromString(this.xmlData).documentElement.getElementsByTagName("field"),i=[],n=0;n<r.length;n++){var c=r[n].getAttribute("id"),o=r[n].getAttribute("x"),f=r[n].getAttribute("y"),l=r[n].getAttribute("width"),h=r[n].getAttribute("height"),u=r[n].getAttribute("xsi:type"),d=r[n].getAttribute("page"),g=r[n].getAttribute("fontName"),m=r[n].getAttribute("fontSize"),p={},b=parseInt(o)-21,v=parseInt(f)-20,y=parseInt(b)+parseInt(l)-4,k=parseInt(v)+parseInt(h)-4;p.fieldType="Tx","Boolean"===u?p.fieldType="Btn":"SSN"!==u&&"Phone"!==u&&"zip"!==u||(p.TName=u.toLowerCase()),p.alternativeText="",p.fullName=c,p.fontSize=m,p.fontName=g,p.subtype="Widget",p.rect=[b,v,y,k],i.push(p),this.ptiPageArray[parseInt(d)]=i}}a()}))}getFields(e){return this.ptiPageArray[e]}}class Y{constructor(e,t,a,r,i,n,c){this.x1=e,this.y1=t,this.x2=a,this.y2=r,this.lineWidth=i||1,this.color=n,this.dashed=c}#b(e,t,a){e.x=z.toFormX(t),e.y=z.toFormY(a)}processLine(e){const a=Math.abs(this.x2-this.x1),r=Math.abs(this.y2-this.y1),i=this.lineWidth;let n={x:0,y:0,w:z.toFixedFloat(this.lineWidth),l:0};const c=z.findColorIndex(this.color),s=c>0&&c<z.colorCount()?{clr:c}:{oc:this.color};if(n={...n,...s},this.dashed&&(n={...n,dsh:1}),r<this.lineWidth&&a>i){if(this.lineWidth<4&&a/this.lineWidth<4)return void t.p2jinfo(`Skipped: short thick HLine: lineWidth = ${this.lineWidth}, xDelta = ${a}`);n.l=z.toFormX(a),this.x1>this.x2?this.#b(n,this.x2,this.y2):this.#b(n,this.x1,this.y1),e.HLines.push(n)}else if(a<this.lineWidth&&r>i){if(this.lineWidth<4&&r/this.lineWidth<4)return void t.p2jinfo(`Skipped: short thick VLine: lineWidth = ${this.lineWidth}, yDelta = ${r}`);n.l=z.toFormY(r),this.y1>this.y2?this.#b(n,this.x2,this.y2):this.#b(n,this.x1,this.y1),e.VLines.push(n)}}}class J{constructor(e,t,a,r,i){this.x=e,this.y=t,this.width=a,this.height=r,this.color=i}processFill(e){const a=z.findColorIndex(this.color),r=a>0&&a<z.colorCount()?{clr:a}:{oc:this.color},i={x:z.toFormX(this.x),y:z.toFormY(this.y),w:z.toFormX(this.width),h:z.toFormY(this.height),...r};i.w<2&&i.h<2?t.p2jinfo(`Skipped: tiny fill: ${i.w} x ${i.h}`):e.Fills.push(i)}}const{round:K,sin:Z,cos:Q,abs:$,sqrt:ee}=Math,te=[];for(let e=0;e<16;e++)for(let t=0;t<16;t++)te[16*e+t]=e.toString(16)+t.toString(16);function ae(e,t){const a=[[1,0,0],[0,1,0],[0,0,1]];for(let r=0;r<3;r++)for(let i=0;i<3;i++){let n=0;for(let a=0;a<3;a++)n+=e[r][a]*t[a][i];a[r][i]=n}return a}function re(e,t){t.fillStyle=e.fillStyle,t.lineCap=e.lineCap,t.lineJoin=e.lineJoin,t.lineWidth=e.lineWidth,t.miterLimit=e.miterLimit,t.shadowBlur=e.shadowBlur,t.shadowColor=e.shadowColor,t.shadowOffsetX=e.shadowOffsetX,t.shadowOffsetY=e.shadowOffsetY,t.strokeStyle=e.strokeStyle,t.globalAlpha=e.globalAlpha,t.arcScaleX_=e.arcScaleX_,t.arcScaleY_=e.arcScaleY_,t.lineScale_=e.lineScale_,t.dashArray=e.dashArray}function ie(e){let t,a=1;if("rgb"===(e=String(e)).substring(0,3)){const r=e.indexOf("(",3),i=e.indexOf(")",r+1),n=e.substring(r+1,i).split(",");t="#";for(let e=0;e<3;e++)t+=te[Number(n[e])];4===n.length&&"a"===e.substring(3,4)&&(a=n[3])}else t=e;return{color:t,alpha:a}}function ne(e,t,a,r){e.currentPath_.push({type:"bezierCurveTo",cp1x:t.x,cp1y:t.y,cp2x:a.x,cp2y:a.y,x:r.x,y:r.y}),e.currentX_=r.x,e.currentY_=r.y}function ce(e,t,a){if(function(e){for(let t=0;t<3;t++)for(let a=0;a<2;a++)if(!isFinite(e[t][a])||isNaN(e[t][a]))return!1;return!0}(t)&&(e.m_=t,a)){const a=t[0][0]*t[1][1]-t[0][1]*t[1][0];e.lineScale_=ee($(a))}}class se{constructor(){}}class oe{constructor(e){this.type_=e,this.x0_=0,this.y0_=0,this.r0_=0,this.x1_=0,this.y1_=0,this.r1_=0,this.colors_=[]}addColorStop(e,t){t=ie(t),this.colors_.push({offset:e,color:t.color,alpha:t.alpha})}}class fe{constructor(e,t,a){this.m_=[[1,0,0],[0,1,0],[0,0,1]],this.mStack_=[],this.aStack_=[],this.currentPath_=[],this.strokeStyle="#000",this.fillStyle="#000",this.lineWidth=1,this.lineJoin="miter",this.lineCap="butt",this.dashArray=[],this.miterLimit=1,this.globalAlpha=1,"HLines"in e&&Array.isArray(e.HLines)||(e.HLines=[]),"VLines"in e&&Array.isArray(e.VLines)||(e.VLines=[]),"Fills"in e&&Array.isArray(e.Fills)||(e.Fills=[]),"Texts"in e&&Array.isArray(e.Texts)||(e.Texts=[]),this.canvas=e,this.width=t,this.height=a,this.arcScaleX_=1,this.arcScaleY_=1,this.lineScale_=1,this.currentFont=null}#v(e,t,a,r){const i=Array.isArray(this.dashArray)&&this.dashArray.length>1;new Y(e.x,e.y,t.x,t.y,a,r,i).processLine(this.canvas)}#y(e,t,a,r){const i=a.x-t.x,n=a.y-t.y;new J(e.x,e.y,i,n,r).processFill(this.canvas)}#k(e,a,r,i){const n=Math.abs(r-Math.abs(i))<1&&r<13;return n&&t.p2jinfo(`Skipped: tiny rect: w=${r}, h=${i}`),n}getContext(e){return"2d"===e?this:null}setLineDash(e){this.dashArray=e}getLineDash(){return this.dashArray}fillText(e,t,a,r,i){if(!e||1===!e.length&&e.trim().length<1)return;const n=this.getCoords_(t,a),c=ie(this.fillStyle||this.strokeStyle),s=c?c.color:"#000000";this.currentFont.processText(n,e,r,s,i,this.canvas,this.m_)}strokeText(e,t,a,r){this.fillText(e,t,a,r)}measureText(e){t.p2jwarn("to be implemented: contextPrototype.measureText - ",e);return{width:(e.length||1)*(this.currentFont.spaceWidth||5)}}setFont(e){this.currentFont&&"function"==typeof this.currentFont.clean&&(this.currentFont.clean(),this.currentFont=null),this.currentFont=new W(e)}clearRect(){t.p2jwarn("to be implemented: contextPrototype.clearRect")}beginPath(){this.currentPath_=[]}moveTo(e,t){const a=this.getCoords_(e,t);this.currentPath_.push({type:"moveTo",x:a.x,y:a.y}),this.currentX_=a.x,this.currentY_=a.y}lineTo(e,t){const a=this.getCoords_(e,t);this.currentPath_.push({type:"lineTo",x:a.x,y:a.y}),this.currentX_=a.x,this.currentY_=a.y}bezierCurveTo(e,t,a,r,i,n){const c=this.getCoords_(i,n);ne(this,this.getCoords_(e,t),this.getCoords_(a,r),c)}quadraticCurveTo(e,t,a,r){const i=this.getCoords_(e,t),n=this.getCoords_(a,r),c={x:this.currentX_+2/3*(i.x-this.currentX_),y:this.currentY_+2/3*(i.y-this.currentY_)};ne(this,c,{x:c.x+(n.x-this.currentX_)/3,y:c.y+(n.y-this.currentY_)/3},n)}arc(e,t,a,r,i,n){const c=n?"at":"wa";let s=e+Q(r)*a;const o=t+Z(r)*a,f=e+Q(i)*a,l=t+Z(i)*a;s!==f||n||(s+=.125);const h=this.getCoords_(e,t),u=this.getCoords_(s,o),d=this.getCoords_(f,l);this.currentPath_.push({type:c,x:h.x,y:h.y,radius:a,xStart:u.x,yStart:u.y,xEnd:d.x,yEnd:d.y})}rect(e,t,a,r){this.#k(e,t,a,r)||(this.moveTo(e,t),this.lineTo(e+a,t),this.lineTo(e+a,t+r),this.lineTo(e,t+r),this.closePath())}strokeRect(e,t,a,r){if(this.#k(e,t,a,r))return;const i=this.currentPath_;this.beginPath(),this.moveTo(e,t),this.lineTo(e+a,t),this.lineTo(e+a,t+r),this.lineTo(e,t+r),this.closePath(),this.stroke(),this.currentPath_=i}fillRect(e,t,a,r){if(this.#k(e,t,a,r))return;const i=this.currentPath_;this.beginPath(),this.moveTo(e,t),this.lineTo(e+a,t),this.lineTo(e+a,t+r),this.lineTo(e,t+r),this.closePath(),this.fill(),this.currentPath_=i}createLinearGradient(e,t,a,r){const i=new oe("gradient");return i.x0_=e,i.y0_=t,i.x1_=a,i.y1_=r,i}createRadialGradient(e,t,a,r,i,n){const c=new oe("gradientradial");return c.x0_=e,c.y0_=t,c.r0_=a,c.x1_=r,c.y1_=i,c.r1_=n,c}drawImage(e,t){}getImageData(e,t,a,r){return{width:a,height:r,data:new Uint8Array(a*r*4)}}stroke(e){if(this.currentPath_.length<2)return;const t=ie(e?this.fillStyle:this.strokeStyle),{color:a}=t,r=this.lineScale_*this.lineWidth,i={x:null,y:null},n={x:null,y:null};for(let t=0;t<this.currentPath_.length;t++){let c=this.currentPath_[t];switch(c.type){case"moveTo":case"bezierCurveTo":case"at":case"wa":break;case"lineTo":e||t>0&&this.#v(this.currentPath_[t-1],c,r,a);break;case"close":e||t>0&&this.#v(this.currentPath_[t-1],this.currentPath_[0],r,a),c=null}e&&c&&((null===i.x||c.x<i.x)&&(i.x=c.x),(null===n.x||c.x>n.x)&&(n.x=c.x),(null===i.y||c.y<i.y)&&(i.y=c.y),(null===n.y||c.y>n.y)&&(n.y=c.y))}e&&this.#y(i,i,n,a)}fill(){this.stroke(!0)}closePath(){this.currentPath_.push({type:"close"})}getCoords_(e,t){const a=this.m_;return{x:e*a[0][0]+t*a[1][0]+a[2][0],y:e*a[0][1]+t*a[1][1]+a[2][1]}}save(){const e={};re(this,e),this.aStack_.push(e),this.mStack_.push(this.m_),this.m_=ae([[1,0,0],[0,1,0],[0,0,1]],this.m_)}restore(){re(this.aStack_.pop(),this),this.m_=this.mStack_.pop()}translate(e,t){ce(this,ae([[1,0,0],[0,1,0],[e,t,1]],this.m_),!1)}rotate(e){const t=Q(e),a=Z(e);ce(this,ae([[t,a,0],[-a,t,0],[0,0,1]],this.m_),!1)}scale(e,t){this.arcScaleX_*=e,this.arcScaleY_*=t;ce(this,ae([[e,0,0],[0,t,0],[0,0,1]],this.m_),!0)}transform(e,t,a,r,i,n){ce(this,ae([[e,t,0],[a,r,0],[i,n,1]],this.m_),!0)}setTransform(e,t,a,r,i,n){ce(this,[[e,t,0],[a,r,0],[i,n,1]],!0)}clip(){}arcTo(){}createPattern(){return new se}}function le(e,t){return new fe({},e,t)}function he(e,t){const a=e.get("AA");if(!a)return;let r=a.get("F");(r||(r=a.get("K"),r))&&r.forEach(((e,a)=>{"JS"===e&&function(e,t){if(Object.prototype.hasOwnProperty.call(t,"TName"))return;if(!e.split)return;const a=e.split("(");if(2!==a.length)return;const r=a[0],i=a[1].split(")")[0];switch(r){case"AFSpecial_Format":t.TName=ue[Number(i)];break;case"AFNumber_Format":t.TName="number";break;case"AFDate_FormatEx":t.TName="date",t.MV=i.replace(/^'+|^"+|'+$|"+$/g,"");break;case"AFSpecial_KeystrokeEx":{const e=i.replace(/^'+|^"+|'+$|"+$/g,"");e&&e.length>0&&e.length<64&&(t.TName="mask",t.MV=e)}break;case"AFPercent_Format":t.TName="percent"}}(a,t)}))}const ue=["zip","zip","phone","ssn",""];class de{static processAnnotation(e,a){"Btn"===a.fieldType?32768&a.fieldFlags?function(e,t){let a="";const r=e.get("Parent");r&&r.forEach(((e,r)=>{"DV"===e?a=r.name||"":"TU"===e?t.alternativeText=r:"TM"===e&&(t.alternativeID=r)})),e.get("AP").get("N").forEach(((e,r)=>{"off"!==e.toLowerCase()&&(t.value=e,t.checked=e===a)})),t.value||(t.value="off")}(e,a):65536&a.fieldFlags?function(e,t){const a=e.get("MK");a&&(t.value=a.get("CA")||""),t.FL="";const r=e.get("A");if(r){const e=r.get("S");t.FL=r.get(e.name)}}(e,a):function(e,t){const a=e.get("AP").get("N");let r=0;a.forEach(((e,a)=>{r++,1===r&&(t.value=e)}))}(e,a):"Ch"===a.fieldType?function(e,t){t.value=e.get("Opt")||[]}(e,a):"Tx"===a.fieldType?he(e,a):"Sig"===a.fieldType?function(e,t){const a=e.get("V");if(!a)return;t.Sig={};const r=a.get("Name");r&&(t.Sig.Name=r);const i=a.get("M");i&&(t.Sig.M=i);const n=a.get("Location");n&&(t.Sig.Location=n);const c=a.get("Reason");c&&(t.Sig.Reason=c);const s=a.get("ContactInfo");s&&(t.Sig.ContactInfo=s)}(e,a):t.p2jwarn("Unknown fieldType: ",a)}}let ge=class{#A="";#w=null;set onload(e){this.#w="function"==typeof e?e:null}get onload(){return this.#w}set src(e){this.#A=e,this.#w&&this.#w()}get src(){return this.#A}btoa(e){return new i.Buffer.from(e,"binary").toString("base64")}};const me={},pe={console:console};var be="undefined"==typeof window,ve=1,ye=[.001,0,0,.001,0,0],ke=0,Ae=1,we=2,xe=3,Se=4;pe.PDFJS||(pe.PDFJS={}),pe.PDFJS.pdfBug=!1;var Ce=me.OPS={dependency:1,setLineWidth:2,setLineCap:3,setLineJoin:4,setMiterLimit:5,setDash:6,setRenderingIntent:7,setFlatness:8,setGState:9,save:10,restore:11,transform:12,moveTo:13,lineTo:14,curveTo:15,curveTo2:16,curveTo3:17,closePath:18,rectangle:19,stroke:20,closeStroke:21,fill:22,eoFill:23,fillStroke:24,eoFillStroke:25,closeFillStroke:26,closeEOFillStroke:27,endPath:28,clip:29,eoClip:30,beginText:31,endText:32,setCharSpacing:33,setWordSpacing:34,setHScale:35,setLeading:36,setFont:37,setTextRenderingMode:38,setTextRise:39,moveText:40,setLeadingMoveText:41,setTextMatrix:42,nextLine:43,showText:44,showSpacedText:45,nextLineShowText:46,nextLineSetSpacingShowText:47,setCharWidth:48,setCharWidthAndBounds:49,setStrokeColorSpace:50,setFillColorSpace:51,setStrokeColor:52,setStrokeColorN:53,setFillColor:54,setFillColorN:55,setStrokeGray:56,setFillGray:57,setStrokeRGBColor:58,setFillRGBColor:59,setStrokeCMYKColor:60,setFillCMYKColor:61,shadingFill:62,beginInlineImage:63,beginImageData:64,endInlineImage:65,paintXObject:66,markPoint:67,markPointProps:68,beginMarkedContent:69,beginMarkedContentProps:70,endMarkedContent:71,beginCompat:72,endCompat:73,paintFormXObjectBegin:74,paintFormXObjectEnd:75,beginGroup:76,endGroup:77,beginAnnotations:78,endAnnotations:79,beginAnnotation:80,endAnnotation:81,paintJpegXObject:82,paintImageMaskXObject:83,paintImageMaskXObjectGroup:84,paintImageXObject:85,paintInlineImageXObject:86,paintInlineImageXObjectGroup:87},Be=me.NO_OPS=[82,83,84,85,86,87],Ie=me.NO_OPS_RANGE=[78,79,80,81],Te=!Boolean(Number(process?.env?.PDF2JSON_DISABLE_LOGS??"0"))&&"console"in pe&&"log"in pe.console?pe.console.log.bind(pe.console):function(){};function Le(e){ve>=5&&(Te("Info: "+e),me.LogManager.notify("info",e))}function Fe(e){ve>=1&&(Te("Warning: "+e),me.LogManager.notify("warn",e))}function Pe(e){if(arguments.length>1){var t=["Error:"];t.push.apply(t,arguments),Te.apply(null,t),e=[].join.call(arguments," ")}throw me.LogManager.notify("error",e),new Error(e)}function Re(e){Fe("TODO: "+e)}function Oe(e,t){e||Pe(t)}function Me(e,t){if(!t)return e;if(t.indexOf(":")>=0)return t;if("/"==t.charAt(0)){var a=e.indexOf("://");return a=e.indexOf("/",a+3),e.substring(0,a)+t}var r=e.length;r=(a=e.lastIndexOf("#"))>=0?a:r,r=(a=e.lastIndexOf("?",r))>=0?a:r;var i=e.lastIndexOf("/",r);return e.substring(0,i+1)+t}function De(e,t){if(!e)return!1;var a=e.indexOf(":");if(a<0)return t;switch(e.substring(0,a)){case"http":case"https":case"ftp":case"mailto":return!0;default:return!1}}function qe(e,t){e||Pe(t)}me.isValidUrl=De;var Ee;me.LogManager=(Ee=[],{addLogger:function(e){Ee.push(e)},notify:function(e,t){for(var a=0,r=Ee.length;a<r;a++){var i=Ee[a];i[e]&&i[e](t)}}});function Ne(e,t,a){return Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!1}),a}var je=me.PasswordResponses={NEED_PASSWORD:1,INCORRECT_PASSWORD:2},Ue=function(){function e(e,t){this.name="PasswordException",this.message=e,this.code=t}return e.prototype=new Error,e.constructor=e,e}(),ze=function(){function e(e,t){this.name="UnknownErrorException",this.message=e,this.details=t}return e.prototype=new Error,e.constructor=e,e}(),He=function(){function e(e){this.name="InvalidPDFException",this.message=e}return e.prototype=new Error,e.constructor=e,e}(),Ge=function(){function e(e){this.name="MissingPDFException",this.message=e}return e.prototype=new Error,e.constructor=e,e}(),_e=function(){function e(e){this.message=e}return e.prototype=new Error,e.prototype.name="NotImplementedException",e.constructor=e,e}(),Xe=function(){function e(e,t){this.begin=e,this.end=t,this.message="Missing data ["+e+", "+t+")"}return e.prototype=new Error,e.prototype.name="MissingDataException",e.constructor=e,e}(),We=function(){function e(e){this.message=e}return e.prototype=new Error,e.prototype.name="XRefParseException",e.constructor=e,e}();function Ve(e){for(var t="",a=e.length,r=0;r<a;++r)t+=String.fromCharCode(e[r]);return t}function Ye(e){for(var t=e.length,a=new Uint8Array(t),r=0;r<t;++r)a[r]=255&e.charCodeAt(r);return a}var Je=[1,0,0,1,0,0],Ke=me.Util=function(){function e(){}return e.makeCssRgb=function(e){return"rgb("+e[0]+","+e[1]+","+e[2]+")"},e.makeCssCmyk=function(t){var a=mt.singletons.cmyk.getRgb(t,0);return e.makeCssRgb(a)},e.transform=function(e,t){return[e[0]*t[0]+e[2]*t[1],e[1]*t[0]+e[3]*t[1],e[0]*t[2]+e[2]*t[3],e[1]*t[2]+e[3]*t[3],e[0]*t[4]+e[2]*t[5]+e[4],e[1]*t[4]+e[3]*t[5]+e[5]]},e.applyTransform=function(e,t){return[e[0]*t[0]+e[1]*t[2]+t[4],e[0]*t[1]+e[1]*t[3]+t[5]]},e.applyInverseTransform=function(e,t){var a=t[0]*t[3]-t[1]*t[2];return[(e[0]*t[3]-e[1]*t[2]+t[2]*t[5]-t[4]*t[3])/a,(-e[0]*t[1]+e[1]*t[0]+t[4]*t[1]-t[5]*t[0])/a]},e.getAxialAlignedBoundingBox=function(t,a){var r=e.applyTransform(t,a),i=e.applyTransform(t.slice(2,4),a),n=e.applyTransform([t[0],t[3]],a),c=e.applyTransform([t[2],t[1]],a);return[Math.min(r[0],i[0],n[0],c[0]),Math.min(r[1],i[1],n[1],c[1]),Math.max(r[0],i[0],n[0],c[0]),Math.max(r[1],i[1],n[1],c[1])]},e.inverseTransform=function(e){var t=e[0]*e[3]-e[1]*e[2];return[e[3]/t,-e[1]/t,-e[2]/t,e[0]/t,(e[2]*e[5]-e[4]*e[3])/t,(e[4]*e[1]-e[5]*e[0])/t]},e.apply3dTransform=function(e,t){return[e[0]*t[0]+e[1]*t[1]+e[2]*t[2],e[3]*t[0]+e[4]*t[1]+e[5]*t[2],e[6]*t[0]+e[7]*t[1]+e[8]*t[2]]},e.singularValueDecompose2dScale=function(e){var t=[e[0],e[2],e[1],e[3]],a=e[0]*t[0]+e[1]*t[2],r=e[0]*t[1]+e[1]*t[3],i=e[2]*t[0]+e[3]*t[2],n=e[2]*t[1]+e[3]*t[3],c=(a+n)/2,s=Math.sqrt((a+n)*(a+n)-4*(a*n-i*r))/2,o=c+s||1,f=c-s||1;return[Math.sqrt(o),Math.sqrt(f)]},e.normalizeRect=function(e){var t=e.slice(0);return e[0]>e[2]&&(t[0]=e[2],t[2]=e[0]),e[1]>e[3]&&(t[1]=e[3],t[3]=e[1]),t},e.intersect=function(e,t){const a=Math.max(Math.min(e[0],e[2]),Math.min(t[0],t[2])),r=Math.min(Math.max(e[0],e[2]),Math.max(t[0],t[2]));if(a>r)return null;const i=Math.max(Math.min(e[1],e[3]),Math.min(t[1],t[3])),n=Math.min(Math.max(e[1],e[3]),Math.max(t[1],t[3]));return i>n?null:[a,i,r,n]},e.sign=function(e){return e<0?-1:1},e.concatenateToArray=function(e,t){Array.prototype.push.apply(e,t)},e.prependToArray=function(e,t){Array.prototype.unshift.apply(e,t)},e.extendObj=function(e,t){for(var a in t)e[a]=t[a]},e.getInheritableProperty=function(e,t){for(;e&&!e.has(t);)e=e.get("Parent");return e?e.get(t):null},e.inherit=function(e,t,a){for(var r in e.prototype=Object.create(t.prototype),e.prototype.constructor=e,a)e.prototype[r]=a[r]},e.loadScript=function(e,t){var a=document.createElement("script"),r=!1;a.setAttribute("src",e),t&&(a.onload=function(){r||t(),r=!0}),document.getElementsByTagName("head")[0].appendChild(a)},e}(),Ze=(me.PageViewport=function(){function e(e,t,a,r,i,n){this.viewBox=e,this.scale=t,this.rotation=a,this.offsetX=r,this.offsetY=i;var c,s,o,f,l,h,u,d,g=(e[2]+e[0])/2,m=(e[3]+e[1])/2;switch(a=(a%=360)<0?a+360:a){case 180:c=-1,s=0,o=0,f=1;break;case 90:c=0,s=1,o=1,f=0;break;case 270:c=0,s=-1,o=-1,f=0;break;default:c=1,s=0,o=0,f=-1}n&&(o=-o,f=-f),0===c?(l=Math.abs(m-e[1])*t+r,h=Math.abs(g-e[0])*t+i,u=Math.abs(e[3]-e[1])*t,d=Math.abs(e[2]-e[0])*t):(l=Math.abs(g-e[0])*t+r,h=Math.abs(m-e[1])*t+i,u=Math.abs(e[2]-e[0])*t,d=Math.abs(e[3]-e[1])*t),this.transform=[c*t,s*t,o*t,f*t,l-c*t*g-o*t*m,h-s*t*g-f*t*m],this.width=u,this.height=d,this.fontScale=t}return e.prototype={clone:function(t){var a="scale"in(t=t||{})?t.scale:this.scale,r="rotation"in t?t.rotation:this.rotation;return new e(this.viewBox.slice(),a,r,this.offsetX,this.offsetY,t.dontFlip)},convertToViewportPoint:function(e,t){return Ke.applyTransform([e,t],this.transform)},convertToViewportRectangle:function(e){var t=Ke.applyTransform([e[0],e[1]],this.transform),a=Ke.applyTransform([e[2],e[3]],this.transform);return[t[0],t[1],a[0],a[1]]},convertToPdfPoint:function(e,t){return Ke.applyInverseTransform([e,t],this.transform)}},e}(),[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,728,711,710,729,733,731,730,732,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8226,8224,8225,8230,8212,8211,402,8260,8249,8250,8722,8240,8222,8220,8221,8216,8217,8218,8482,64257,64258,321,338,352,376,381,305,322,339,353,382,0,8364]);function Qe(e){var t,a=e.length,r="";if("þ"===e[0]&&"ÿ"===e[1])for(t=2;t<a;t+=2)r+=String.fromCharCode(e.charCodeAt(t)<<8|e.charCodeAt(t+1));else for(t=0;t<a;++t){var i=Ze[e.charCodeAt(t)];r+=i?String.fromCharCode(i):e.charAt(t)}return r}function $e(e){for(var t in e)return!1;return!0}function et(e){return"boolean"==typeof e}function tt(e){return"number"==typeof e&&(0|e)==e}function at(e){return"number"==typeof e}function rt(e){return"string"==typeof e}function it(e){return e instanceof Vt}function nt(e,t){return e instanceof Yt&&(!t||e.cmd==t)}function ct(e,t){if(!(e instanceof Jt))return!1;if(!t)return!0;var a=e.get("Type");return it(a)&&a.name==t}function st(e){return e instanceof Array}function ot(e){return"object"==typeof e&&null!=e&&"getBytes"in e}function ft(e){return"object"==typeof e&&null!=e&&"byteLength"in e}function lt(e){return e instanceof Kt}function ht(e){var t;if("object"!=typeof e)return!1;if(ct(e))t=e;else{if(!ot(e))return!1;t=e.dict}return t.has("FunctionType")}var ut=me.Promise=function(){var e={handlers:[],running:!1,unhandledRejections:[],pendingRejectionCheck:!1,scheduleHandlers:function(e){0!=e._status&&(this.handlers=this.handlers.concat(e._handlers),e._handlers=[],this.running||(this.running=!0,setTimeout(this.runHandlers.bind(this),0)))},runHandlers:function(){for(;this.handlers.length>0;){var e=this.handlers.shift(),t=e.thisPromise._status,a=e.thisPromise._value;try{1===t?"function"==typeof e.onResolve&&(a=e.onResolve(a)):"function"==typeof e.onReject&&(a=e.onReject(a),t=1,e.thisPromise._unhandledRejection&&this.removeUnhandeledRejection(e.thisPromise))}catch(e){t=2,a=e}e.nextPromise._updateStatus(t,a)}this.running=!1},addUnhandledRejection:function(e){this.unhandledRejections.push({promise:e,time:Date.now()}),this.scheduleRejectionCheck()},removeUnhandeledRejection:function(e){e._unhandledRejection=!1;for(var t=0;t<this.unhandledRejections.length;t++)this.unhandledRejections[t].promise===e&&(this.unhandledRejections.splice(t),t--)},scheduleRejectionCheck:function(){this.pendingRejectionCheck||(this.pendingRejectionCheck=!0,setTimeout(function(){this.pendingRejectionCheck=!1;for(var e=Date.now(),t=0;t<this.unhandledRejections.length;t++)if(e-this.unhandledRejections[t].time>500){var a=this.unhandledRejections[t].promise._value,r="Unhandled rejection: "+a;a.stack&&(r+="\n"+a.stack),Fe(r),this.unhandledRejections.splice(t),t--}this.unhandledRejections.length&&this.scheduleRejectionCheck()}.bind(this),500))}};function t(){this._status=0,this._handlers=[]}return t.all=function(e){var a=new t,r=e.length,i=[];if(0===r)return a.resolve(i),a;function n(e){2!==a._status&&(i=[],a.reject(e))}for(var c=0,s=e.length;c<s;++c){var o=e[c],f=function(e){return function(t){2!==a._status&&(i[e]=t,0===--r&&a.resolve(i))}}(c);t.isPromise(o)?o.then(f,n):f(o)}return a},t.isPromise=function(e){return e&&"function"==typeof e.then},t.prototype={_status:null,_value:null,_handlers:null,_unhandledRejection:null,_updateStatus:function(a,r){1!==this._status&&2!==this._status&&(1==a&&t.isPromise(r)?r.then(this._updateStatus.bind(this,1),this._updateStatus.bind(this,2)):(this._status=a,this._value=r,2===a&&0===this._handlers.length&&(this._unhandledRejection=!0,e.addUnhandledRejection(this)),e.scheduleHandlers(this)))},get isResolved(){return 1===this._status},get isRejected(){return 2===this._status},resolve:function(e){this._updateStatus(1,e)},reject:function(e){this._updateStatus(2,e)},then:function(a,r){var i=new t;return this._handlers.push({thisPromise:this,onResolve:a,onReject:r,nextPromise:i}),e.scheduleHandlers(this),i}},t}(),dt=function(){function e(e,t,a){for(;e.length<a;)e+=t;return e}function t(){this.started={},this.times=[],this.enabled=!0}return t.prototype={time:function(e){this.enabled&&(e in this.started&&Fe("Timer is already running for "+e),this.started[e]=Date.now())},timeEnd:function(e){this.enabled&&(e in this.started||Fe("Timer has not been started for "+e),this.times.push({name:e,start:this.started[e],end:Date.now()}),delete this.started[e])},toString:function(){for(var t=this.times,a="",r=0,i=0,n=t.length;i<n;++i){var c=t[i].name;c.length>r&&(r=c.length)}for(i=0,n=t.length;i<n;++i){var s=t[i],o=s.end-s.start;a+=e(s.name," ",r)+" "+o+"ms\n"}return a}},t}();function gt(e,t){this.name=e,this.comObj=t,this.callbackIndex=1,this.postMessageTransfers=!0;var a=this.callbacks={},r=this.actionHandler={};r.console_log=[function(e){Te.apply(null,e)}],r.console_error="console"in pe?[function(e){pe.console.error.apply(null,e)}]:[function(e){Te.apply(null,e)}],r._warn=[function(e){Fe(e)}],"object"==typeof t&&(t.onmessage=function(e){var i=e.data;if(i.isReply){var n=i.callbackId;if(i.callbackId in a){var c=a[n];delete a[n],c(i.data)}else Pe("Cannot resolve callback "+n)}else if(i.action in r){var s=r[i.action];if(i.callbackId){var o=new ut;o.then((function(e){t.postMessage({isReply:!0,callbackId:i.callbackId,data:e})})),s[0].call(s[1],i.data,o)}else s[0].call(s[1],i.data)}else Pe("Unkown action from worker: "+i.action)})}me.createBlob=function(e,t){return new i.Blob([e],{type:t})},me.createObjectURL=function(){if("undefined"!=typeof URL&&URL.createObjectURL)return function(e,t){var a=me.createBlob(e,t);return URL.createObjectURL(a)};var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";return function(t,a){for(var r="data:"+a+";base64,",i=0,n=t.length;i<n;i+=3){var c=255&t[i],s=255&t[i+1],o=255&t[i+2];r+=e[c>>2]+e[(3&c)<<4|s>>4]+e[i+1<n?(15&s)<<2|o>>6:64]+e[i+2<n?63&o:64]}return r}}(),gt.prototype={on:function(e,t,a){var r=this.actionHandler;r[e]&&Pe('There is already an actionName called "'+e+'"'),r[e]=[t,a]},send:function(e,t,a,r){var i={action:e,data:t};if(a){var n=this.callbackIndex++;this.callbacks[n]=a,i.callbackId=n}r&&this.postMessageTransfers?this.comObj.postMessage(i,r):this.comObj.postMessage(i)}},t.p2jlog=Te,t.p2jinfo=Le,t.p2jwarn=Fe,t.p2jerror=Pe,t.verbosity=function(e){ve=isNaN(e)?1:e<=0?0:e>=5?5:e},t.verbosity();var mt=function(){function e(){Pe("should not call ColorSpace constructor")}return e.prototype={getRgb:function(e,t){Pe("Should not call ColorSpace.getRgb")},getRgbItem:function(e,t,a,r){Pe("Should not call ColorSpace.getRgbItem")},getRgbBuffer:function(e,t,a,r,i,n){Pe("Should not call ColorSpace.getRgbBuffer")},getOutputLength:function(e){Pe("Should not call ColorSpace.getOutputLength")},isPassthrough:function(e){return!1},createRgbBuffer:function(e,t,a,r){if(this.isPassthrough(r))return e.subarray(t);var i=new Uint8Array(3*a),n=1<<r;if(1===this.numComps&&a>n&&"DeviceGray"!==this.name&&"DeviceRGB"!==this.name){for(var c=r<=8?new Uint8Array(n):new Uint16Array(n),s=0;s<n;s++)c[s]=s;var o=new Uint8Array(3*n);this.getRgbBuffer(c,0,n,o,0,r);var f=0;for(s=0;s<a;++s){var l=3*e[t++];i[f++]=o[l],i[f++]=o[l+1],i[f++]=o[l+2]}return i}return this.getRgbBuffer(e,t,a,i,0,r),i},usesZeroToOneRange:!0},e.parse=function(t,a,r){var i=e.parseToIR(t,a,r);return i instanceof pt?i:e.fromIR(i)},e.fromIR=function(t){var a=st(t)?t[0]:t;switch(a){case"DeviceGrayCS":return this.singletons.gray;case"DeviceRgbCS":return this.singletons.rgb;case"DeviceCmykCS":return this.singletons.cmyk;case"CalGrayCS":var r=t[1].WhitePoint,i=t[1].BlackPoint,n=t[1].Gamma;return new wt(r,i,n);case"PatternCS":var c=t[1];return c&&(c=e.fromIR(c)),new bt(c);case"IndexedCS":var s=t[1],o=t[2],f=t[3];return new vt(e.fromIR(s),o,f);case"AlternateCS":var l=t[1],h=t[2],u=t[3];return new pt(l,e.fromIR(h),Lt.fromIR(u));case"LabCS":r=t[1].WhitePoint,i=t[1].BlackPoint;var d=t[1].Range;return new xt(r,i,d);default:Pe("Unkown name "+a)}return null},e.parseToIR=function(t,a,r){if(it(t)){var i=r.get("ColorSpace");if(ct(i)){var n=i.get(t.name);n&&(t=n)}}var c;if(it(t=a.fetchIfRef(t)))switch(c=t.name,this.mode=c,c){case"DeviceGray":case"G":return"DeviceGrayCS";case"DeviceRGB":case"RGB":return"DeviceRgbCS";case"DeviceCMYK":case"CMYK":return"DeviceCmykCS";case"Pattern":return["PatternCS",null];default:Pe("unrecognized colorspace "+c)}else if(st(t))switch(c=t[0].name,this.mode=c,c){case"DeviceGray":case"G":return"DeviceGrayCS";case"DeviceRGB":case"RGB":case"CalRGB":return"DeviceRgbCS";case"DeviceCMYK":case"CMYK":return"DeviceCmykCS";case"CalGray":return["CalGrayCS",t[1].getAll()];case"ICCBased":if(1==(u=a.fetchIfRef(t[1]).dict.get("N")))return"DeviceGrayCS";if(3==u)return"DeviceRgbCS";if(4==u)return"DeviceCmykCS";break;case"Pattern":var s=t[1];return s&&(s=e.parseToIR(s,a,r)),["PatternCS",s];case"Indexed":case"I":var o=e.parseToIR(t[1],a,r),f=t[2]+1,l=a.fetchIfRef(t[3]);return ot(l)&&(l=l.getBytes()),["IndexedCS",o,f,l];case"Separation":case"DeviceN":var h=t[1],u=1;return it(h)?u=1:st(h)&&(u=h.length),["AlternateCS",u,e.parseToIR(t[2],a,r),Lt.getIR(a,a.fetchIfRef(t[3]))];case"Lab":return["LabCS",t[1].getAll()];default:Pe('unimplemented color space object "'+c+'"')}else Pe('unrecognized color space object: "'+t+'"');return null},e.isDefaultDecode=function(e,t){if(!e)return!0;if(2*t!==e.length)return Fe("The decode map is not the correct length"),!0;for(var a=0,r=e.length;a<r;a+=2)if(0!==e[a]||1!=e[a+1])return!1;return!0},e.singletons={get gray(){return Ne(this,"gray",new yt)},get rgb(){return Ne(this,"rgb",new kt)},get cmyk(){return Ne(this,"cmyk",new At)}},e}(),pt=function(){function e(e,t,a){this.name="Alternate",this.numComps=e,this.defaultColor=new Float32Array(e);for(var r=0;r<e;++r)this.defaultColor[r]=1;this.base=t,this.tintFn=a}return e.prototype={getRgb:function(e,t){var a=new Uint8Array(3);return this.getRgbItem(e,t,a,0),a},getRgbItem:function(e,t,a,r){this.base.numComps;var i="subarray"in e?e.subarray(t,t+this.numComps):Array.prototype.slice.call(e,t,t+this.numComps),n=this.tintFn(i);this.base.getRgbItem(n,0,a,r)},getRgbBuffer:function(e,t,a,r,i,n){for(var c=this.tintFn,s=this.base,o=1/((1<<n)-1),f=s.numComps,l=s.usesZeroToOneRange,h=s.isPassthrough(8)||!l,u=h?i:0,d=h?r:new Uint8Array(f*a),g=this.numComps,m=new Float32Array(g),p=0;p<a;p++){for(var b=0;b<g;b++)m[b]=e[t++]*o;var v=c(m);if(l)for(b=0;b<f;b++)d[u++]=255*v[b];else s.getRgbItem(v,0,d,u),u+=f}h||s.getRgbBuffer(d,0,a,r,i,8)},getOutputLength:function(e){return this.base.getOutputLength(e*this.base.numComps/this.numComps)},isPassthrough:mt.prototype.isPassthrough,createRgbBuffer:mt.prototype.createRgbBuffer,isDefaultDecode:function(e){return mt.isDefaultDecode(e,this.numComps)},usesZeroToOneRange:!0},e}(),bt=function(){function e(e){this.name="Pattern",this.base=e}return e.prototype={},e}(),vt=function(){function e(e,t,a){this.name="Indexed",this.numComps=1,this.defaultColor=new Uint8Array([0]),this.base=e,this.highVal=t;var r,i=e.numComps*t;if(ot(a)){r=new Uint8Array(i);var n=a.getBytes(i);r.set(n)}else if(rt(a)){r=new Uint8Array(i);for(var c=0;c<i;++c)r[c]=a.charCodeAt(c)}else a instanceof Uint8Array||a instanceof Array?r=a:Pe("Unrecognized lookup table: "+a);this.lookup=r}return e.prototype={getRgb:function(e,t){var a=this.base.numComps,r=e[t]*a;return this.base.getRgb(this.lookup,r)},getRgbItem:function(e,t,a,r){var i=this.base.numComps,n=e[t]*i;this.base.getRgbItem(this.lookup,n,a,r)},getRgbBuffer:function(e,t,a,r,i){for(var n=this.base,c=n.numComps,s=n.getOutputLength(c),o=this.lookup,f=0;f<a;++f){var l=e[t++]*c;n.getRgbBuffer(o,l,1,r,i,8),i+=s}},getOutputLength:function(e){return this.base.getOutputLength(e*this.base.numComps)},isPassthrough:mt.prototype.isPassthrough,createRgbBuffer:mt.prototype.createRgbBuffer,isDefaultDecode:function(e){return!0},usesZeroToOneRange:!0},e}(),yt=function(){function e(){this.name="DeviceGray",this.numComps=1,this.defaultColor=new Float32Array([0])}return e.prototype={getRgb:function(e,t){var a=new Uint8Array(3);return this.getRgbItem(e,t,a,0),a},getRgbItem:function(e,t,a,r){var i=255*e[t]|0;i=i<0?0:i>255?255:i,a[r]=a[r+1]=a[r+2]=i},getRgbBuffer:function(e,t,a,r,i,n){for(var c=255/((1<<n)-1),s=t,o=i,f=0;f<a;++f){var l=c*e[s++]|0;r[o++]=l,r[o++]=l,r[o++]=l}},getOutputLength:function(e){return 3*e},isPassthrough:mt.prototype.isPassthrough,createRgbBuffer:mt.prototype.createRgbBuffer,isDefaultDecode:function(e){return mt.isDefaultDecode(e,this.numComps)},usesZeroToOneRange:!0},e}(),kt=function(){function e(){this.name="DeviceRGB",this.numComps=3,this.defaultColor=new Float32Array([0,0,0])}return e.prototype={getRgb:function(e,t){var a=new Uint8Array(3);return this.getRgbItem(e,t,a,0),a},getRgbItem:function(e,t,a,r){var i=255*e[t]|0,n=255*e[t+1]|0,c=255*e[t+2]|0;a[r]=i<0?0:i>255?255:i,a[r+1]=n<0?0:n>255?255:n,a[r+2]=c<0?0:c>255?255:c},getRgbBuffer:function(e,t,a,r,i,n){var c=3*a;if(8!=n)for(var s=255/((1<<n)-1),o=t,f=i,l=0;l<c;++l)r[f++]=s*e[o++]|0;else r.set(e.subarray(t,t+c),i)},getOutputLength:function(e){return e},isPassthrough:function(e){return 8==e},createRgbBuffer:mt.prototype.createRgbBuffer,isDefaultDecode:function(e){return mt.isDefaultDecode(e,this.numComps)},usesZeroToOneRange:!0},e}(),At=function(){function e(e,t,a,r,i){var n=e[t+0]*a,c=e[t+1]*a,s=e[t+2]*a,o=e[t+3]*a,f=n*(-4.387332384609988*n+54.48615194189176*c+18.82290502165302*s+212.25662451639585*o-285.2331026137004)+c*(1.7149763477362134*c-5.6096736904047315*s+-17.873870861415444*o-5.497006427196366)+s*(-2.5217340131683033*s-21.248923337353073*o+17.5119270841813)+o*(-21.86122147463605*o-189.48180835922747)+255,l=n*(8.841041422036149*n+60.118027045597366*c+6.871425592049007*s+31.159100130055922*o-79.2970844816548)+c*(-15.310361306967817*c+17.575251261109482*s+131.35250912493976*o-190.9453302588951)+s*(4.444339102852739*s+9.8632861493405*o-24.86741582555878)+o*(-20.737325471181034*o-187.80453709719578)+255,h=n*(.8842522430003296*n+8.078677503112928*c+30.89978309703729*s-.23883238689178934*o-14.183576799673286)+c*(10.49593273432072*c+63.02378494754052*s+50.606957656360734*o-112.23884253719248)+s*(.03296041114873217*s+115.60384449646641*o-193.58209356861505)+o*(-22.33816807309886*o-180.12613974708367)+255;r[i]=f>255?255:f<0?0:f,r[i+1]=l>255?255:l<0?0:l,r[i+2]=h>255?255:h<0?0:h}function t(){this.name="DeviceCMYK",this.numComps=4,this.defaultColor=new Float32Array([0,0,0,1])}return t.prototype={getRgb:function(t,a){var r=new Uint8Array(3);return e(t,a,1,r,0),r},getRgbItem:function(t,a,r,i){e(t,a,1,r,i)},getRgbBuffer:function(t,a,r,i,n,c){for(var s=1/((1<<c)-1),o=0;o<r;o++)e(t,a,s,i,n),a+=4,n+=3},getOutputLength:function(e){return 3*(e>>2)},isPassthrough:mt.prototype.isPassthrough,createRgbBuffer:mt.prototype.createRgbBuffer,isDefaultDecode:function(e){return mt.isDefaultDecode(e,this.numComps)},usesZeroToOneRange:!0},t}(),wt=function(){function e(e,t,a){this.name="CalGray",this.numComps=3,this.defaultColor=new Float32Array([0,0,0]),e||Pe("WhitePoint missing - required for color space CalGray"),t=t||[0,0,0],a=a||1,this.XW=e[0],this.YW=e[1],this.ZW=e[2],this.XB=t[0],this.YB=t[1],this.ZB=t[2],this.G=a,(this.XW<0||this.ZW<0||1!==this.YW)&&Pe("Invalid WhitePoint components for "+this.name+", no fallback available"),(this.XB<0||this.YB<0||this.ZB<0)&&(Le("Invalid BlackPoint for "+this.name+", falling back to default"),this.XB=this.YB=this.ZB=0),0===this.XB&&0===this.YB&&0===this.ZB||Re(this.name+", BlackPoint: XB: "+this.XB+", YB: "+this.YB+", ZB: "+this.ZB+", only default values are supported."),this.G<1&&(Le("Invalid Gamma: "+this.G+" for "+this.name+", falling back to default"),this.G=1)}return e.prototype={getRgb:function(e,t){var a=new Uint8Array(3);return this.getRgbItem(e,t,a,0),a},getRgbItem:function(e,t,a,r){var i=e[t],n=Math.pow(i,this.G),c=(this.XW,this.YW*n),s=(this.ZW,Math.max(116*Math.pow(c,1/3)-16,0));a[r]=255*s/100,a[r+1]=255*s/100,a[r+2]=255*s/100},getRgbBuffer:function(e,t,a,r,i,n){for(var c=255/((1<<n)-1),s=t,o=i,f=0;f<a;++f){var l=c*e[s++]|0;r[o++]=l,r[o++]=l,r[o++]=l}},getOutputLength:function(e){return 3*e},isPassthrough:mt.prototype.isPassthrough,createRgbBuffer:mt.prototype.createRgbBuffer,isDefaultDecode:function(e){return mt.isDefaultDecode(e,this.numComps)},usesZeroToOneRange:!0},e}(),xt=function(){function e(e,t,a){this.name="Lab",this.numComps=3,this.defaultColor=new Float32Array([0,0,0]),e||Pe("WhitePoint missing - required for color space Lab"),t=t||[0,0,0],a=a||[-100,100,-100,100],this.XW=e[0],this.YW=e[1],this.ZW=e[2],this.amin=a[0],this.amax=a[1],this.bmin=a[2],this.bmax=a[3],this.XB=t[0],this.YB=t[1],this.ZB=t[2],(this.XW<0||this.ZW<0||1!==this.YW)&&Pe("Invalid WhitePoint components, no fallback available"),(this.XB<0||this.YB<0||this.ZB<0)&&(Le("Invalid BlackPoint, falling back to default"),this.XB=this.YB=this.ZB=0),(this.amin>this.amax||this.bmin>this.bmax)&&(Le("Invalid Range, falling back to defaults"),this.amin=-100,this.amax=100,this.bmin=-100,this.bmax=100)}function t(e){return e>=6/29?e*e*e:108/841*(e-4/29)}function a(e,t,a,r){return a+e*(r-a)/t}function r(e,r,i,n,c,s){var o=r[i],f=r[i+1],l=r[i+2];!1!==n&&(o=a(o,n,0,100),f=a(f,n,e.amin,e.amax),l=a(l,n,e.bmin,e.bmax));var h,u,d,g=(o+16)/116,m=g+(f=f>e.amax?e.amax:f<e.amin?e.amin:f)/500,p=g-(l=l>e.bmax?e.