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 • 937 kB
JavaScript
import e from"node:fs";import{readFile as t}from"node:fs/promises";import{EventEmitter as a}from"node:events";import{Buffer as r,Blob as i}from"node:buffer";import{Transform as n,Readable as c}from"node:stream";import s from"node:process";import o from"node:console";class f{constructor(e){this.nodeName=e,this.childNodes=[],this.attributes={},this.textContent=""}getAttribute(e){return this.attributes[e]||null}getElementsByTagName(e){let t=[];this.nodeName===e&&t.push(this);for(const a of this.childNodes)if(a instanceof f){"*"!==e&&a.nodeName!==e||t.push(a);const r=a.getElementsByTagName(e);t=t.concat(r)}return t}}class l{constructor(){this.documentElement=null}}class h{parseFromString(e){const t=new l;return e=e.replace(/<\?xml[^?]*\?>/,"").trim(),t.documentElement=this.parseElement(e),t}parseElement(e){const t=/<([^\s/>]+)([^>]*)>/,a=/([^\s=]+)=(?:"([^"]*)"|'([^']*)')/g,r=e.match(t);if(!r)return null;const i=r[1],n=r[2],c=new f(i);let s;for(;null!==(s=a.exec(n));){const e=s[1],t=s[2]||s[3];c.attributes[e]=t}const o=r[0].length,l=new RegExp(`</${i}>`),h=e.slice(o).search(l);if(-1===h)return c;let u=e.slice(o,o+h).trim();for(;u.length>0;){if(u.startsWith("<")&&!u.startsWith("</")){const e=u.match(t);if(e){const t=e[1],a=new RegExp(`</${t}>`),r=u.search(a);if(-1!==r){const e=t.length+3,a=u.slice(0,r+e),i=this.parseElement(a);i&&c.childNodes.push(i),u=u.slice(a.length).trim();continue}}}const e=u.indexOf("<");if(-1===e){c.textContent+=u.trim();break}if(!(e>0))break;c.textContent+=u.slice(0,e).trim(),u=u.slice(e).trim()}return c}}const u={log:o.log.bind(o),info:o.info.bind(o),warn:o.warn.bind(o),error(e){throw new Error(e)},verbosity(){},LogManager:{addLogger(){},notify(){}},ERRORS:0,WARNINGS:1,INFOS:5};function d(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=g[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 g=["zip","zip","phone","ssn",""];class m{static processAnnotation(e,t){"Btn"===t.fieldType?32768&t.fieldFlags?function(e,t){const a=e.get("Parent");a&&a.forEach((e,a)=>{"DV"===e||("TU"===e?t.alternativeText=a:"TM"===e&&(t.alternativeID=a))}),e.get("AP").get("N").forEach((e,a)=>{"off"!==e.toLowerCase()&&(t.value=e,t.checked=t.fieldValue===t.value)}),t.value||(t.value="off")}(e,t):65536&t.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,t):function(e,t){const a=e.get("AP").get("N");let r=0;a.forEach((e,a)=>{r++,1===r&&(t.value=e)})}(e,t):"Ch"===t.fieldType?function(e,t){t.value=e.get("Opt")||[]}(e,t):"Tx"===t.fieldType?d(e,t):"Sig"===t.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,t):u.warn("Unknown fieldType: ",t)}}let p=class{#e="";#t=null;set onload(e){this.#t="function"==typeof e?e:null}get onload(){return this.#t}set src(e){this.#e=e,this.#t&&this.#t()}get src(){return this.#e}btoa(e){return new r.from(e,"binary").toString("base64")}};const b=["#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"],v=["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"],y=[[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]],k=96/72;class A{static toFixedFloat(e){return parseFloat(e.toFixed(3))}static colorCount(){return b.length}static toPixelX(e){return Math.round(24*e)}static toPixelY(e){return Math.round(24*e)}static pointToPixel(e){return e*k}static getColorByIndex(e){return b[e]}static toFormPoint(e,t){return[e/24,t/24]}static toFormX(e){return A.toFixedFloat(e/24)}static toFormY(e){return A.toFixedFloat(e/24)}static findColorIndex(e){return 4===e.length&&(e+="000"),b.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 w{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}#a(e,t,a){e.x=A.toFormX(t),e.y=A.toFormY(a)}processLine(e){const t=Math.abs(this.x2-this.x1),a=Math.abs(this.y2-this.y1),r=this.lineWidth;let i={x:0,y:0,w:A.toFixedFloat(this.lineWidth),l:0};const n=A.findColorIndex(this.color),c=n>0&&n<A.colorCount()?{clr:n}:{oc:this.color};if(i={...i,...c},this.dashed&&(i={...i,dsh:1}),a<this.lineWidth&&t>r){if(this.lineWidth<4&&t/this.lineWidth<4)return void u.info(`Skipped: short thick HLine: lineWidth = ${this.lineWidth}, xDelta = ${t}`);i.l=A.toFormX(t),this.x1>this.x2?this.#a(i,this.x2,this.y2):this.#a(i,this.x1,this.y1),e.HLines.push(i)}else if(t<this.lineWidth&&a>r){if(this.lineWidth<4&&a/this.lineWidth<4)return void u.info(`Skipped: short thick VLine: lineWidth = ${this.lineWidth}, yDelta = ${a}`);i.l=A.toFormY(a),this.y1>this.y2?this.#a(i,this.x2,this.y2):this.#a(i,this.x1,this.y1),e.VLines.push(i)}}}class x{constructor(e,t,a,r,i){this.x=e,this.y=t,this.width=a,this.height=r,this.color=i}processFill(e){const t=A.findColorIndex(this.color),a=t>0&&t<A.colorCount()?{clr:t}:{oc:this.color},r={x:A.toFormX(this.x),y:A.toFormY(this.y),w:A.toFormX(this.width),h:A.toFormY(this.height),...a};r.w<2&&r.h<2?u.info(`Skipped: tiny fill: ${r.w} x ${r.h}`):e.Fills.push(r)}}const S=["bd","bold","demi","black","medi"],C=["arial","helvetica","sans-serif ","courier ","monospace ","ocr "],T=.1;class I{#r(){let e=this.fontObj.name||this.fontObj.fallbackName;return e||(e=v[0]),e=e.toLowerCase(),e}#i(){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=S.indexOf(a)>=0,e=e[0]}return{subType:e,bold:t}}#n(){const e=this.typeName.indexOf("symbol")>0||v[2].indexOf(this.subType)>=0;if(this.fontObj.isSymbolicFont){C.filter(e=>this.typeName.indexOf(e)>=0).length>0&&(this.fontObj.isSymbolicFont=!1,u.info(`Reset: isSymbolicFont (false) for ${this.fontObj.name}`))}else e&&(this.fontObj.isSymbolicFont=!0,u.info(`Reset: isSymbolicFont (true) for ${this.fontObj.name}`));return e}#c(){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=A.toFormX(e)/32,e}constructor(e){this.fontObj=e,this.typeName=this.#r();const{subType:t,bold:a}=this.#i();this.subType=t,this.bold=a,this.isSymbol=this.#n(),this.spaceWidth=this.#c(),this.fontSize=1,this.faceIdx=0,this.italic=!1,this.fontStyleId=-1}static compareBlockPos(e,t){if(e.y<t.y-T)return-1;if(Math.abs(e.y-t.y)<=T){if(e.x<t.x-T)return-1;if(Math.abs(e.x-t.x)<=T)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 I.getFontSize(e)/12*e.sw}static areAdjacentBlocks(e,t){const a=Math.abs(e.y-t.y)<=T,r=t.x-e.x-e.w<I.getSpaceThreshHold(e);return a&&r}static getFontSize(e){const t=e.R[0].S;return t<0?e.R[0].TS[1]:y[t][1]}static areDuplicateBlocks(e,t){return e.x===t.x&&e.y===t.y&&e.R[0].T===t.R[0].T&&I.haveSameStyle(e,t)}#s(){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?v[1].indexOf(t)>=0&&(this.faceIdx=1):v[2].indexOf(this.subType)>=0?this.faceIdx=2:e.isMonospace?(this.faceIdx=3,v[4].indexOf(t)>=0?this.faceIdx=4:v[5].indexOf(t)>=0&&(this.faceIdx=5)):e.isSymbolicFont&&(this.faceIdx=2),0===this.faceIdx&&this.typeName.indexOf("narrow")>0&&(this.faceIdx=1),u.info(`typeName = ${t} => faceIdx = ${this.faceIdx}`)}#o(e){this.#s(),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 y.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}#f(e){let t=e;if(!e||1!==e.length)return t;if(!this.fontObj.isSymbolicFont||!this.isSymbol)return"C"!==t&&"G"!==t||(t=` ${t} `),t;switch(e.charCodeAt(0)){case 20:t="✓";break;case 70:t="CIDFontType0"===this.fontObj.type?"⚠":"}";break;case 71:case 97:t="▶";break;case 99:t=this.isSymbol?"•":"▲";break;case 100:t="▼";break;case 103:t="➨";break;case 106:t="";break;case 114:case 116:case 118:t="•";break;case 115:t="▲";break;default:u.info(`${this.fontObj.type} - SymbolicFont - (${this.fontObj.name}) : ${e.charCodeAt(0)}::${e.charCodeAt(1)} => ${t}`)}return t}#l(e){if(!e||1!==e.length||"Type3"!==this.fontObj.type)return e;if(u.info(`Processing Type3 font: char code = ${e.charCodeAt(0)}, char = '${e}'`),this.fontObj.charProcMapping)u.info(`charProcMapping available with ${Object.keys(this.fontObj.charProcMapping).length} entries`);else if(u.info("No charProcMapping available for this Type3 font"),e&&1===e.length){const t=e.charCodeAt(0);if(t>=65&&t<=90)return u.info(`Using direct uppercase letter: ${e}`),e;if(t>=97&&t<=122)return u.info(`Using direct lowercase letter: ${e}`),e;if(t>=48&&t<=57)return u.info(`Using direct digit: ${e}`),e}if(this.fontObj.charProcMapping){const t=e.charCodeAt(0),a=this.fontObj.charProcMapping[t];if(a){u.info(`Found glyph name in mapping: ${a}`);const e={bullet:"•",checkbox:"☐",checkmark:"✓",check:"✓",circle:"○",square:"□",triangle:"▲",triangledown:"▼",triangleleft:"◀",triangleright:"▶",star:"★",diamond:"◆",heart:"♥",club:"♣",spade:"♠",filledcircle:"●",filledsquare:"■",filledtriangle:"▲",filledtriangledown:"▼",filledtriangleright:"▶",filledtriangleleft:"◀",arrowleft:"←",arrowright:"→",arrowup:"↑",arrowdown:"↓",cross:"✗"},t="string"==typeof a?a.toLowerCase():"";if(t in e){const a=e[t];return u.info(`Mapped ${t} to Unicode ${a}`),a}if("string"==typeof a&&a.length>1){const e=a.match(/[A-Za-z]/g);if(e&&1===e.length){const t=e[0].toUpperCase();return u.info(`Extracted letter ${t} from glyph name ${a}`),t}}for(const a in e)if(t.indexOf(a)>=0){const r=e[a];return u.info(`Partial match: ${t} contains ${a}, mapped to ${r}`),r}if("string"==typeof a){const e=a.match(/[A-Za-z]/g);if(e&&1===e.length){const t=e[0].toUpperCase();return u.info(`Extracted letter ${t} from glyph name ${a}`),t}const t=a.match(/\d+/);if(t&&1===t.length){const e=parseInt(t[0],10);if(e>=1&&e<=26){const t=String.fromCharCode(64+e);return u.info(`Mapped number ${e} in glyph name ${a} to letter ${t}`),t}}}if("string"==typeof a&&a.startsWith("uni")){const e=a.substring(3);if(/^[0-9A-F]{4,6}$/i.test(e))return u.info(`Mapped uni${e} to Unicode character`),String.fromCharCode(parseInt(e,16))}}}const t=e.charCodeAt(0);u.info(`No direct mapping for character code ${t}, checking general mappings`);let a=e;switch(t){case 18:a="✓";break;case 19:a="☐";break;case 20:a="☑";break;case 108:a="•";break;case 109:a="●";break;case 110:a="○";break;case 111:a="■";break;case 112:a="□";break;case 113:a="▲";break;case 114:a="▼";break;case 117:a="←";break;case 118:a="→";break;case 119:a="↑";break;case 120:a="↓";break;case 128:a="∞";break;case 129:a="≠";break;case 130:a="≤";break;case 131:a="≥"}return a!==e?u.info(`Mapped char code ${t} to Unicode ${a}`):u.info(`No mapping found for char code ${t}, returning original character`),a}#h(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,t,a,r,i,n,c){u.info(`Processing text: '${t}', font type: ${this.fontObj.type||"unknown"}, char code: ${t?t.charCodeAt(0):"none"}`);const s=t;let o="Type3"===this.fontObj.type?this.#l(t):this.#f(t);o||(u.info("Text processing returned null or empty, falling back to original text"),o=s),u.info(`Processed text: '${t}' -> '${o}'`),this.fontStyleId=this.#o(i);const f=[this.faceIdx,this.fontSize,this.bold?1:0,this.italic?1:0],l=A.findColorIndex(r),h=l>=0&&l<A.colorCount()?{clr:l}:{oc:r};let d={T:this.flashEncode(o),S:this.fontStyleId,TS:f};const g=this.#h(c);0!==g&&(u.info(`${t}: rotated ${g} degree.`),d=Object.assign({},d,{RA:g}));const m={x:A.toFormX(e.x)-.25,y:A.toFormY(e.y)-.75,w:A.toFixedFloat(a),...h,sw:this.spaceWidth,A:"left",R:[d]};u.info(`Adding text to output: '${o}'`),n.Texts.push(m)}flashEncode(e){if(!e)return e;let t=e;return t=t.replace(/\u0096/g,"-"),t=t.replace(/\u0091/g,"'"),t=t.replace(/\u0092/g,"'"),t=t.replace(/\u0082/g,"'"),t=t.replace(/\u0093/g,'"'),t=t.replace(/\u0094/g,'"'),t=t.replace(/\u0084/g,'"'),t=t.replace(/\u008B/g,"«"),t=t.replace(/\u009B/g,"»"),t}clean(){this.fontObj=null,delete this.fontObj}}const{round:B,sin:L,cos:F,abs:P,sqrt:R}=Math,O=[];for(let e=0;e<16;e++)for(let t=0;t<16;t++)O[16*e+t]=e.toString(16)+t.toString(16);function D(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 M(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 q(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+=O[Number(n[e])];4===n.length&&"a"===e.substring(3,4)&&(a=n[3])}else t=e;return{color:t,alpha:a}}function E(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 N(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_=R(P(a))}}class j{constructor(){}}class U{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=q(t),this.colors_.push({offset:e,color:t.color,alpha:t.alpha})}}class z{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}#u(e,t,a,r){const i=Array.isArray(this.dashArray)&&this.dashArray.length>1;new w(e.x,e.y,t.x,t.y,a,r,i).processLine(this.canvas)}#d(e,t,a,r){const i=a.x-t.x,n=a.y-t.y;new x(e.x,e.y,i,n,r).processFill(this.canvas)}#g(e,t,a,r){const i=Math.abs(a-Math.abs(r))<1&&a<13;return i&&u.info(`Skipped: tiny rect: w=${a}, h=${r}`),i}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=q(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){u.warn("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 I(e)}clearRect(){u.warn("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);E(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_)};E(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+F(r)*a;const o=t+L(r)*a,f=e+F(i)*a,l=t+L(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.#g(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.#g(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.#g(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 U("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 U("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=q(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.#u(this.currentPath_[t-1],c,r,a);break;case"close":e||t>0&&this.#u(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.#d(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={};M(this,e),this.aStack_.push(e),this.mStack_.push(this.m_),this.m_=D([[1,0,0],[0,1,0],[0,0,1]],this.m_)}restore(){M(this.aStack_.pop(),this),this.m_=this.mStack_.pop()}translate(e,t){N(this,D([[1,0,0],[0,1,0],[e,t,1]],this.m_),!1)}rotate(e){const t=F(e),a=L(e);N(this,D([[t,a,0],[-a,t,0],[0,0,1]],this.m_),!1)}scale(e,t){this.arcScaleX_*=e,this.arcScaleY_*=t;N(this,D([[e,0,0],[0,t,0],[0,0,1]],this.m_),!0)}transform(e,t,a,r,i,n){N(this,D([[e,t,0],[a,r,0],[i,n,1]],this.m_),!0)}setTransform(e,t,a,r,i,n){N(this,[[e,t,0],[a,r,0],[i,n,1]],!0)}clip(){}arcTo(){}createPattern(){return new j}}function H(e,t){return new z({},e,t)}const G={disableWorker:!0},_={console:console,PDFJS:G};var X="undefined"==typeof window,W=1,V=[.001,0,0,.001,0,0],J=0,Y=1,K=2,Z=3,$=4;_.PDFJS||(_.PDFJS={}),_.PDFJS.pdfBug=!1;var Q=G.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},ee=G.NO_OPS=[82,83,84,85,86,87],te=G.NO_OPS_RANGE=[78,79,80,81],ae=!Boolean(Number(process?.env?.PDF2JSON_DISABLE_LOGS??"0"))&&"console"in _&&"log"in _.console?_.console.log.bind(_.console):function(){};function re(e){W>=5&&(ae("Info: "+e),G.LogManager.notify("info",e))}function ie(e){W>=1&&(ae("Warning: "+e),G.LogManager.notify("warn",e))}function ne(e){if(arguments.length>1){var t=["Error:"];t.push.apply(t,arguments),ae.apply(null,t),e=[].join.call(arguments," ")}throw G.LogManager.notify("error",e),new Error(e)}function ce(e){ie("TODO: "+e)}function se(e,t){e||ne(t)}function oe(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 fe(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 le(e,t){e||ne(t)}G.isValidUrl=fe;var he;G.LogManager=(he=[],{addLogger:function(e){he.push(e)},notify:function(e,t){for(var a=0,r=he.length;a<r;a++){var i=he[a];i[e]&&i[e](t)}}});function ue(e,t,a){return Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!1}),a}var de=G.PasswordResponses={NEED_PASSWORD:1,INCORRECT_PASSWORD:2},ge=function(){function e(e,t){this.name="PasswordException",this.message=e,this.code=t}return e.prototype=new Error,e.constructor=e,e}(),me=function(){function e(e,t){this.name="UnknownErrorException",this.message=e,this.details=t}return e.prototype=new Error,e.constructor=e,e}(),pe=function(){function e(e){this.name="InvalidPDFException",this.message=e}return e.prototype=new Error,e.constructor=e,e}(),be=function(){function e(e){this.name="MissingPDFException",this.message=e}return e.prototype=new Error,e.constructor=e,e}(),ve=function(){function e(e){this.message=e}return e.prototype=new Error,e.prototype.name="NotImplementedException",e.constructor=e,e}(),ye=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}(),ke=function(){function e(e){this.message=e}return e.prototype=new Error,e.prototype.name="XRefParseException",e.constructor=e,e}();function Ae(e){for(var t="",a=e.length,r=0;r<a;++r)t+=String.fromCharCode(e[r]);return t}function we(e){for(var t=e.length,a=new Uint8Array(t),r=0;r<t;++r)a[r]=255&e.charCodeAt(r);return a}var xe=[1,0,0,1,0,0],Se=G.Util=function(){function e(){}return e.makeCssRgb=function(e){return"rgb("+e[0]+","+e[1]+","+e[2]+")"},e.makeCssCmyk=function(t){var a=Ge.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}(),Ce=(G.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 Se.applyTransform([e,t],this.transform)},convertToViewportRectangle:function(e){var t=Se.applyTransform([e[0],e[1]],this.transform),a=Se.applyTransform([e[2],e[3]],this.transform);return[t[0],t[1],a[0],a[1]]},convertToPdfPoint:function(e,t){return Se.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 Te(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=Ce[e.charCodeAt(t)];r+=i?String.fromCharCode(i):e.charAt(t)}return r}function Ie(e){for(var t in e)return!1;return!0}function Be(e){return"boolean"==typeof e}function Le(e){return"number"==typeof e&&(0|e)==e}function Fe(e){return"number"==typeof e}function Pe(e){return"string"==typeof e}function Re(e){return e instanceof At}function Oe(e,t){return e instanceof wt&&(!t||e.cmd==t)}function De(e,t){if(!(e instanceof xt))return!1;if(!t)return!0;var a=e.get("Type");return Re(a)&&a.name==t}function Me(e){return e instanceof Array}function qe(e){return"object"==typeof e&&null!=e&&"getBytes"in e}function Ee(e){return"object"==typeof e&&null!=e&&"byteLength"in e}function Ne(e){return e instanceof St}function je(e){var t;if("object"!=typeof e)return!1;if(De(e))t=e;else{if(!qe(e))return!1;t=e.dict}return t.has("FunctionType")}var Ue=G.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),ie(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}(),ze=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&&ie("Timer is already running for "+e),this.started[e]=Date.now())},timeEnd:function(e){this.enabled&&(e in this.started||ie("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 He(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){ae.apply(null,e)}],r.console_error="console"in _?[function(e){_.console.error.apply(null,e)}]:[function(e){ae.apply(null,e)}],r._warn=[function(e){ie(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 ne("Cannot resolve callback "+n)}else if(i.action in r){var s=r[i.action];if(i.callbackId){var o=new Ue;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 ne("Unkown action from worker: "+i.action)})}G.createBlob=function(e,t){return new i([e],{type:t})},G.createObjectURL=function(){if("undefined"!=typeof URL&&URL.createObjectURL)return function(e,t){var a=G.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}}(),He.prototype={on:function(e,t,a){var r=this.actionHandler;r[e]&&ne('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)}},G.log=ae,G.info=re,G.warn=ie,G.error=ne,G.verbosity=function(e){W=isNaN(e)?1:e<=0?0:e>=5?5:e},G.verbosity();var Ge=function(){function e(){ne("should not call ColorSpace constructor")}return e.prototype={getRgb:function(e,t){ne("Should not call ColorSpace.getRgb")},getRgbItem:function(e,t,a,r){ne("Should not call ColorSpace.getRgbItem")},getRgbBuffer:function(e,t,a,r,i,n){ne("Should not call ColorSpace.getRgbBuffer")},getOutputLength:function(e){ne("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 _e?i:e.fromIR(i)},e.fromIR=function(t){var a=Me(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 Ke(r,i,n);case"PatternCS":var c=t[1];return c&&(c=e.fromIR(c)),new Xe(c);case"IndexedCS":var s=t[1],o=t[2],f=t[3];return new We(e.fromIR(s),o,f);case"AlternateCS":var l=t[1],h=t[2],u=t[3];return new _e(l,e.fromIR(h),rt.fromIR(u));case"LabCS":r=t[1].WhitePoint,i=t[1].BlackPoint;var d=t[1].Range;return new Ze(r,i,d);default:ne("Unkown name "+a)}return null},e.parseToIR=function(t,a,r){if(Re(t)){var i=r.get("ColorSpace");if(De(i)){var n=i.get(t.name);n&&(t=n)}}var c;if(Re(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:ne("unrecognized colorspace "+c)}else if(Me(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 De(d=a.fetchIfRef(t[1]))&&(d=d.getAll()),["CalGrayCS",d];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 qe(l)&&(l=l.getBytes()),["IndexedCS",o,f,l];case"Separation":case"DeviceN":var h=t[1],u=1;return Re(h)?u=1:Me(h)&&(u=h.length),["AlternateCS",u,e.parseToIR(t[2],a,r),rt.getIR(a,a.fetchIfRef(t[3]))];case"Lab":var d;return De(d=a.fetchIfRef(t[1]))&&(d=d.getAll()),["LabCS",d];default:ne('unimplemented color space object "'+c+'"')}else ne('unrecognized color space object: "'+t+'"');return null},e.isDefaultDecode=function(e,t){if(!e)return!0;if(2*t!==e.length)return ie("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 ue(this,"gray",new Ve)},get rgb(){return ue(this,"rgb",new Je)},get cmyk(){return ue(this,"cmyk",new Ye)}},e}(),_e=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:Ge.prototype.isPassthrough,createRgbBuffer:Ge.prototype.createRgbBuffer,isDefaultDecode:function(e){return Ge.isDefaultDecode(e,this.numComps)},usesZeroToOneRange:!0},e}(),Xe=function(){function e(e){this.name="Pattern",this.base=e}return e.prototype={},e}(),We=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(qe(a)){r=new Uint8Array(i);var n=a.getBytes(i);r.set(n)}else if(Pe(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:ne("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:Ge.prototype.isPassthrough,createRgbBuffer:Ge.prototype.createRgbBuffer,isDefaultDecode:function(e){return!0},usesZeroToOneRange:!0},e}(),Ve=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:Ge.prototype.isPassthrough,createRgbBuffer:Ge.prototype.createRgbBuffer,isDefaultDecode:function(e){return Ge.isDefaultDecode(e,this.numComps)},usesZeroToOneRange:!0},e}(),Je=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:Ge.prototype.createRgbBuffer,isDefaultDecode:function(e){return Ge.isDefaultDecode(e,this.numComps)},usesZeroToOneRange:!0},e}(),Ye=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:Ge.prototype.isPassthrough,createRgbBuffer:Ge.prototype.createRgbBuffer,isDefaultDecode:function(e){return Ge.isDefaultDecode(e,this.numComps)},usesZeroToOneRange:!0},t}(),Ke=function(){function e(e,t,a){this.name="CalGray",this.numComps=3,this.defaultColor=new Float32Array([0,0,0]),e||ne("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)&&ne("Invalid WhitePoint components for "+this.name+", no fallback available"),(this.XB<0||this.YB<0||this.ZB<0)&&(re("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||ce(this.name+", BlackPoint: XB: "+this.XB+", YB: "+this.YB+", ZB: "+this.ZB+", only default values are supported."),this.G<1&&(re("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:Ge.prototype.isPassthrough,createRgbBuffer:Ge.prototype.createRgbBuffer,isDefaultDecode:function(e){return Ge.isDefaultDecode(e,this.numComps)},usesZeroToOneRange:!0},e}(),Ze=function(){function e(e,t,a){this.name="Lab",this.numComps=3,this.defaultColor=new Float32Array([0,0,0]),e||ne("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)&&ne("Invalid WhitePoint components, no fallback available"),(this.XB<0||this.YB<0||this.ZB<0)&&(re("Invalid BlackPoint, falling back to default"),this.XB=this.YB=this.ZB=0),(this.amin>this.amax||this.bmin>this.bmax)&&(re("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.bmax:l<e.bmin?e.bmin:l)/200,b=e.XW*t(m),v=e.YW*t(g),y=e.ZW*t(p);e.ZW<1?(h=3.1339*b+-1.617*v+-.4906*y,u=-.9785*b+1.916*v+.0333*y,d=.072*b+-.229*v+1.4057*y):(h=3.2406*b+-1.5372*v+-.4986*y,u=-.9689*b+1.8758*v+.0415*y,d=.0557*b+-.204*v+1.057*y),c[s]=255*Math.sqrt(h<0?0:h>1?1:h),c[s+1]=255*Math.sqrt(u<0?0:u>1?1:u),c[s+2]=255*Math.sqrt(d<0?0:d>1?1:d)}return e.prototype={getRgb:function(e,t){var a=new Uint8Array(3);return r(this,e,t,!1,a,0),a},getRgbItem:function(e,t,a,i){r(this,e,t,!1,a,i)},getRgbBuffer:function(e,t,a,i,n,c){for(var s=(1<<c)-1,o=0;o<a;o++)r(this,e,t,s,i,n),t+=3,n+=3},getOutputLength:function(e){return e},createRgbBuffer:Ge.prototype.createRgbBuffer,isPassthrough:Ge.prototype.isPassthrough,isDefaultDecode:function(e){return!0},usesZeroToOneRange:!1},e}(),$e=2,Qe=3,et=function(){function e(){ne("should not call Pattern constructor")}return e.prototype={getPattern:function(e){ne("Should not call Pattern.getStyle: "+e)}},e.shadingFromIR=function(e){return tt[e[0]].fromIR(e)},e.parseShading=function(e,t,a,r){var i=qe(e)?e.dict:e,n=i.get("ShadingType");switch(n){case $e:case Qe:return new tt.RadialAxial(i,t,a,r);default:return ce("Unsupported shading type: "+n),new tt.Dummy}},e}(),tt={SMALL_NUMBER:.01};tt.RadialAxial=function(){function e(e,t,a,r,i){this.matrix=t,this.coordsArr=e.get("Coords"),this.shadingType=e.get("ShadingType"),this.type="Pattern",this.ctx=i;var n=e.get("ColorSpace","CS");n=Ge.parse(n,a,r),this.cs=n;var c=0,s=1;if(e.has("Domain")){var o=e.get("Domain");c=o[0],s=o[1]}var f=!1,l=!1;if(e.has("Extend")){var h=e.get("Extend");f=h[0],l=h[1]}if(!(this.shadingType!==Qe||f&&l)){var u=this.coordsArr[0],d=this.coordsArr[1],g=this.coordsArr[2],m=this.coordsArr[3],p=this.coordsArr[4],b=this.coordsArr[5],v=Math.sqrt((u-m)*(u-m)+(d-p)*(d-p));g<=b+v&&b<=g+v&&ie("Unsupported radial gradient.")}this.extendStart=f,this.extendEnd=l;var y,k=e.get("Function");if(Me(k)){for(var A=[],w=0,x=k.length;w<x;w++){var S=a.fetchIfRef(k[w]);je(S)||ne("Invalid function"),A.push(rt.parse(a,S))}y=function(e){for(var t=[],a=0,r=A.length;a<r;a++)t.push(A[a](e)[0]);return t}}else je(k)||ne("Invalid function"),y=rt.parse(a,k);var C=s-c,T=C/10,I=this.colorStops=[];if(c>=s||T<=0)re("Bad shading domain.");else{for(var B=c;B<=s;B+=T){var L=n.getRgb(y([B]),0),F=Se.makeCssRgb(L);I.push([(B-c)/C,F])}var P="transparent";if(e.has("Background")){L=n.getRgb(e.get("Background"),0);P=Se.makeCssRgb(L)}f||(I.unshift([0,P]),I[1][0]+=tt.SMALL_NUMBER),l||(I[I.length-1][0]-=tt.SMALL_NUMBER,I.push([1,P])),this.colorStops=I}}return e.fromIR=function(e){var t=e[1],a=e[2],r=e[3],i=e[4],n=e[5],c=e[6];return{type:"Pattern",getPattern:function(e){var s;t==$e?s=e.createLinearGradient(r[0],r[1],i[0],i[1]):t==Qe&&(s=e.createRadialGradient(r[0],r[1],n,i[0],i[1],c));for(var o=0,f=a.length;o<f;++o){var l=a[o];s.addColorStop(l[0],l[1])}return s}}},e.prototype={getIR:function(){var e=this.coordsArr,t=this.shadingType;if(t==$e)var a=[e[0],e[1]],r=[e[2],e[3]],i=null,n=null;else if(t==Qe)a=[e[0],e[1]],r=[e[3],e[4]],i=e[2],n=e[5];else ne("getPattern type unknown: "+t);var c=this.matrix;return c&&(a=Se.applyTransform(a,c),r=Se.applyTransform(r,c)),["RadialAxial",t,this.colorStops,a,r,i,n]}},e}(),tt.Dummy=function(){function e(){this.type="Pattern"}return e.fromIR=function(){return{type:"Pattern",getPattern:function(){return"hotpink"}}},e.prototype={getIR:function(){return["Dummy"]}},e}();var at=function(){var e=1,t=2;function a(e,t,a,r,i,n){this.name=e[1][0].name,this.operatorList=e[2],this.matrix=e[3]||[1,0,0,1,0,0],this.bbox=e[4],this.xstep=e[5],this.ystep=e[6],this.paintType=e[7],this.tilingType=e[8],this.color=t,this.objs=r,this.commonObjs=i,this.base