PageSourceSearch

https://localpdf.online/app/assets/index-Co9e3Gtx.js

js localpdf.online collected 2026-10-02 01:09:05 UTC 16,057 bytes, 6 lines download raw bytes

1import{c as Pt}from"./qpdf-engine--OFF57Gq.js";import{f as Bt,Q as Ht}from"./worker-entrypoint-Cpi_3YOf.js";const dt=[80,75],V=[208,207,17,224,161,177,26,225],tt='"Noto Sans","Apple Color Emoji","Segoe UI Emoji","Noto Color Emoji","Segoe UI Symbol","Arial Unicode MS","Noto Sans Symbols 2","Noto Sans CJK SC","Noto Sans CJK JP","Noto Sans Devanagari","PingFang SC","Hiragino Sans","Yu Gothic","Microsoft YaHei","Mangal","Kohinoor Devanagari",sans-serif';function Dt(t){return t.length>=2&&t[0]===dt[0]&&t[1]===dt[1]}function Lt(t){if(t.length<V.length)return!1;for(let e=0;e<V.length;e+=1)if(t[e]!==V[e])return!1;return!0}function Ut(t){return t.replace(/&nbsp;/gi," ").replace(/&amp;/gi,"&").replace(/&lt;/gi,"<").replace(/&gt;/gi,">").replace(/&quot;/gi,'"').replace(/&#39;/gi,"'")}function at(t){return t.replace(/\r/g,"").replace(/\t/g," ").replace(/[ ]+/g," ").trim()}function O(t){const e=Ut(t.replace(/<[^>]+>/g," "));return at(e.replace(/\breturn\s+true\s*;\s*}/gi," ").replace(/\bfunction\s+\w+\s*\([^)]*\)\s*{/gi," "))}function bt(t,e){const a=e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),o=new RegExp(`${a}\\s*=\\s*["']([^"']+)["']`,"i").exec(t);return(o==null?void 0:o[1])??""}function et(t){return t.replace(/<a\b([^>]*)>([\s\S]*?)<\/a>/gi,(e,a,n)=>{const o=bt(a,"href").trim(),r=O(n);return r.length===0?o.length>0?o:"":o.length===0?r:`${r} (${o})`})}function Et(t){const e=[],a=/<tr[^>]*>([\s\S]*?)<\/tr>/gi;let n=a.exec(t);for(;n;){const o=n[1],r=/<(?:td|th)[^>]*>([\s\S]*?)<\/(?:td|th)>/gi,i=[];let w=r.exec(o);for(;w;){const h=O(et(w[1]));h.length>0&&i.push(h),w=r.exec(o)}i.length>0&&e.push(i.join(" | ")),n=a.exec(t)}return e}function $t(t){const e=t.replace(/<script[\s\S]*?<\/script>/gi," ").replace(/<style[\s\S]*?<\/style>/gi," ").replace(/<!--[\s\S]*?-->/g," ").replace(/\n/g," "),a=[],n=/<(h1|h2|h3|p|table|ol|ul)\b[^>]*>[\s\S]*?<\/\1>|<img\b[^>]*>/gi;let o=n.exec(e);for(;o;){const i=o[0];if(/^<img\b/i.exec(i)){const p=bt(i,"src");p.startsWith("data:image/")?a.push({kind:"image",text:"[Image]",imageDataUrl:p}):a.push({kind:"image",text:"[Image omitted in local mode]"}),o=n.exec(e);continue}const h=/^<(h1|h2|h3|p|table|ol|ul)\b[^>]*>([\s\S]*?)<\/\1>$/i.exec(i);if(!h){o=n.exec(e);continue}const c=h[1].toLowerCase(),u=h[2];if(c==="table"){const p=Et(u);p.length>0&&a.push({kind:"table",text:p.join(`
2`)}),o=n.exec(e);continue}if(c==="ol"||c==="ul"){const p=/<li\b[^>]*>([\s\S]*?)<\/li>/gi;let F=p.exec(u),d=1;for(;F;){const R=O(et(F[1]));if(R.length>0){const $=c==="ol"?`${d}. `:"• ";a.push({kind:"list",text:`${$}${R}`}),d+=1}F=p.exec(u)}o=n.exec(e);continue}const S=O(et(u));if(S.length===0){o=n.exec(e);continue}c==="h1"?a.push({kind:"heading1",text:S,headingLevel:1}):c==="h2"?a.push({kind:"heading2",text:S,headingLevel:2}):c==="h3"?a.push({kind:"heading3",text:S,headingLevel:3}):a.push({kind:"paragraph",text:S}),o=n.exec(e)}if(a.length>0)return a;const r=O(e);return r.length===0?[{kind:"blank",text:""}]:r.split(`
3`).map(i=>at(i)).filter(i=>i.length>0).map(i=>({kind:"paragraph",text:i}))}function Wt(t,e){return t==="high"?{defaultFontSize:12,lineHeight:1.45,paragraphGap:6,leftRightMargin:48,topBottomMargin:52,compressStreams:!e}:t==="min"?{defaultFontSize:10,lineHeight:1.25,paragraphGap:4,leftRightMargin:36,topBottomMargin:42,compressStreams:!e}:{defaultFontSize:11,lineHeight:1.35,paragraphGap:5,leftRightMargin:42,topBottomMargin:48,compressStreams:!e}}function It(t){const e=t==null?void 0:t.quality,a=e==="high"||e==="min"?e:"standard",n=(t==null?void 0:t.pdfA)===!0,o=(t==null?void 0:t.protectWithPassword)===!0,r=typeof(t==null?void 0:t.password)=="string"?t.password.trim():"",i=(t==null?void 0:t.searchablePdf)!==!1;return{quality:a,pdfA:n,protectWithPassword:o,password:r,searchablePdf:i}}function Nt(t,e){const a=Math.max(.65,Math.min(1,e));return{defaultFontSize:Math.max(8.5,t.defaultFontSize*a),lineHeight:Math.max(1.08,t.lineHeight*(.95+a*.05)),paragraphGap:Math.max(2,Math.round(t.paragraphGap*a)),leftRightMargin:Math.max(18,Math.round(t.leftRightMargin*a)),topBottomMargin:Math.max(20,Math.round(t.topBottomMargin*a)),compressStreams:t.compressStream
3s}}function Ot(t,e){return t==="heading1"?Math.round(e*1.7):t==="heading2"?Math.round(e*1.45):t==="heading3"?Math.round(e*1.25):t==="table"?Math.max(9,Math.round(e*.95)):e}function K(t,e){return t==="heading1"?e.paragraphGap+4:t==="heading2"?e.paragraphGap+3:t==="heading3"||t==="table"?e.paragraphGap+2:t==="blank"?e.paragraphGap+4:e.paragraphGap}function mt(t,e,a,n,o,r){return t-a>=n?t:(o(),r()-e)}function jt(t){if(typeof atob=="function"){const e=atob(t),a=new Uint8Array(e.length);for(let n=0;n<e.length;n+=1)a[n]=e.charCodeAt(n);return a}throw new Error("Base64 decoding is unavailable in this runtime")}function Gt(t){const e=/^data:([^;]+);base64,(.+)$/i.exec(t.trim());if(!e)return null;const a=e[1].toLowerCase(),n=e[2];return{mimeType:a,bytes:jt(n)}}async function X(t){let e=t;if(typeof self<"u"&&self.location&&!t.startsWith("http://")&&!t.startsWith("https://")&&!t.startsWith("blob:")&&!t.startsWith("data:")){const n=self.location.protocol==="blob:"?self.location.origin:self.location.href;e=new URL(t,n).href}const a=await fetch(e);if(!a.ok)throw new Error(`Failed to load font: ${e}`);return new Uint8Array(await a.arrayBuffer())}async function zt(){const[t,e,a]=await Promise.all([import("./noto-sans-latin-400-normal-DgXudELe.js"),import("./noto-sans-cyrillic-400-normal-BviOoXf6.js"),import("./noto-sans-cyrillic-ext-400-normal-DaPpRN-b.js")]);return{latinUrl:t.default,cyrillicUrl:e.default,cyrillicExtUrl:a.default}}function Mt(t){return new RegExp("\\p{Script=Cyrillic}","u").test(t)}function qt(t){return/[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}]/u.test(t)}function Kt(t){return new RegExp("\\p{Script=Devanagari}","u").test(t)}function _t(t){return Mt(t)||qt(t)||Kt(t)}function pt(t,e){return!e&&_t(t)}function nt(t,e){const a=Math.max(1,Math.round(t)),n=Math.max(1,Math.round(e));if(typeof OffscreenCanvas<"u"){const o=new OffscreenCanvas(a,n),r=o.getContext("2d");return r?{canvas:o,context:r}:null}if(typeof document<"u"){const o=document.createElement("canvas");o.width=a,o.height=n;const r=o.getContext("2d");if(r)return{canvas:o,context:r}}return null}async function Z(t,e,a,n,o){const r=nt(Math.max(16,e),Math.max(16,a+10));if(!r)return null;const i=r.context,w=o?"700":"400";i.font=`${w} ${n}px ${tt}`;const h=i.measureText(t),c=Math.max(8,Math.ceil(h.width)+6),u=Math.min(Math.max(8,e),c),S=Math.max(a+8,Math.ceil(n*1.5)),p=nt(u,S);if(!p)return null;const{canvas:F,context:d}=p;d.clearRect(0,0,u,S),d.fillStyle="#111",d.textBaseline="top",d.font=`${w} ${n}px ${tt}`,d.fillText(t,0,1,u);let R=null;return typeof OffscreenCanvas<"u"&&F instanceof OffscreenCanvas?R=await F.convertToBlob({type:"image/png"}):typeof HTMLCanvasElement<"u"&&F instanceof HTMLCanvasElement&&(R=await new Promise(j=>F.toBlob(j,"image/png"))),R?{bytes:new Uint8Array(await R.arrayBuffer()),width:u,height:S}:null}function Jt(t,e,a,n){const o=t.split(`
4`),r=[];for(const i of o){const w=i.trim();if(w.length===0)continue;const h=w.split(/\s+/);let c="";for(const u of h){const S=c.length>0?`${c} ${u}`:u;if(e.widthOfTextAtSize(S,a)<=n){c=S;continue}if(c.length>0&&r.push(c),e.widthOfTextAtSize(u,a)<=n){c=u;continue}let p="";for(const F of Array.from(u)){const d=`${p}${F}`;e.widthOfTextAtSize(d,a)<=n?p=d:(p.length>0&&r.push(p),p=F)}c=p}c.length>0&&r.push(c)}return r.length>0?r:[""]}function xt(t,e,a){const n=nt(Math.max(16,e),Math.max(16,Math.ceil(a*1.6)));if(!n)return t.split(`
5`).map(i=>i.trim()).filter(i=>i.length>0);const o=n.context;o.font=`${a}px ${tt}`;const r=[];for(const i of t.split(`
6`)){const w=i.trim();if(w.length===0)continue;let h="";for(const c of Array.from(w)){const u=`${h}${c}`;o.measureText(u).width<=e?h=u:(h.length>0&&r.push(h),h=c)}h.length>0&&r.push(h)}return r.length>0?r:[""]}function wt(t,e,a){let n=0;for(const o of Array.from(e))St(t,o,a)&&(n+=1);return n}function St(t,e,a){if(typeof t.widthOfTextAtSize!="function")return!1;try{const n=t.widthOfTextAtSize(e.length>0?e:" ",a);return Number.isFinite(n)}catch{return!1}}function Qt(t,e,a){return St(t,e,a)}function Yt(t){return t>=126976&&t<=129791||t>=8592&&t<=8703||t>=8960&&t<=9215||t>=9312&&t<=9471||t>=9632&&t<=9727||t>=9728&&t<=10175||t>=11008&&t<=11263||t===8205||t===65039}function yt(t){const e=t.codePointAt(0);return typeof e!="number"?!1:Yt(e)}async function Vt(t,e){const a={arrayBuffer:e};try{const[n,o]=await Promise.all([t.convertToHtml(a),t.extractRawText(a)]);return{html:n.value,text:o.value}}catch(n){const o=typeof Buffer<"u",r=n instanceof Error?n.message:"";if(!(o&&/could not find file in options/i.test(r)))throw n;const w={buffer:Buffer.from(e)},[h,c]=await Promise.all([t.convertToHtml(w),t.extractRawText(w)]);return{html:h.value,text:c.value}}}function Xt(t,e,a,n,o){const{PDFName:r,PDFNumber:i,PDFArray:w}=t,h=r.of("Annots"),c=e.context.obj([i.of(n.x),i.of(n.y),i.of(n.x+n.width),i.of(n.y+n.height)]),u=e.context.obj([i.of(0),i.of(0),i.of(0)]),S=e.context.obj([o,r.of("Fit")]),p=e.context.obj({S:r.of("GoTo"),D:S}),F=e.context.obj({Type:r.of("Annot"),Subtype:r.of("Link"),Rect:c,Border:u,A:p}),d=e.context.register(F);let R=a.node.lookupMaybe(h,w);if(!R){const $=e.context.obj([]);a.node.set(h,$),R=$}R.push(d)}function Zt(t,e,a,n,o){const{PDFName:r,PDFNumber:i,PDFString:w,PDFArray:h}=t,c=r.of("Annots"),u=e.context.obj([i.of(n.x),i.of(n.y),i.of(n.x+n.width),i.of(n.y+n.height)]),S=e.context.obj([i.of(0),i.of(0),i.of(0)]),p=e.context.obj({S:r.of("URI"),URI:w.of(o)}),F=e.context.obj({Type:r.of("Annot"),Subtype:r.of("Link"),Rect:u,Border:S,A:p}),d=e.context.register(F);let R=a.node.lookupMaybe(c,h);if(!R){const $=e.context.obj([]);a.node.set(c,$),R=$}R.push(d)}async function te(t,e,a){if(!e.protectWithPassword)return t;if(!e.password)throw new Ht("PROTECT_INVALID_OPTIONS","Password is required when protection is enabled.");
6return(await a()).encrypt(t,{userPassword:e.password,ownerPassword:e.password,keyLength:256})}async function ee({inputIds:t,fs:e,options:a,emitProgress:n},o){if(t.length===0)throw new Error("Word to PDF requires at least one input file");const r=It(a),i=await import("./index-EReD-Y9T.js").then(function(d){return d.i}),{PDFDocument:w,StandardFonts:h,PDFArray:c,PDFName:u,PDFNumber:S,PDFString:p}=await import("./worker-entrypoint-Cpi_3YOf.js").then(function(d){return d.r}),F=[];for(let d=0;d<t.length;d+=1){const R=await e.read(t[d]),j=await(await R.getBlob()).arrayBuffer(),rt=new Uint8Array(j);if(Lt(rt))throw new Error("Legacy .doc is not supported in secure local mode. Save as .docx and retry.");if(!Dt(rt))throw new Error(`Unsupported Word file format for ${t[d]}. Please upload a .docx file.`);const ot=await Vt(i,j),G=$t(ot.html);if(G.length===1&&G[0].kind==="blank"){const l=at(ot.text);l.length>0&&(G[0]={kind:"paragraph",text:l})}const it=Wt(r.quality,r.pdfA),_=[595.28,841.89],Tt=[1],At=async l=>{var ut;const m=await w.create();m.setTitle(`${R.getName().replace(/\.[^.]+$/,"")||"Document"} (Converted)`),m.setCreator("LocalPDF"),m.setSubject(r.pdfA?"Archive conversion profile (best-effort)":"Word to PDF conversion"),m.setKeywords(r.pdfA?["word","pdf","pdfa","best-effort"]:["word","pdf","conversion"]);let L=await m.embedFont(h.Helvetica),z=L,q=L;try{m.registerFontkit(Bt);const{latinUrl:s,cyrillicUrl:f,cyrillicExtUrl:x}=await zt(),[y,T,U]=await Promise.all([X(s),X(f),X(x)]);L=await m.embedFont(y,{subset:!0}),z=await m.embedFont(T,{subset:!0}),q=await m.embedFont(U,{subset:!0})}catch{}const W=(s,f=12)=>{const y=Mt(s)?[z,q,L]:[L,z,q];for(const A of y)if(Qt(A,s,f))return A;let T=L,U=wt(L,s,f);for(const A of[z,q]){const k=wt(A,s,f);k>U&&(T=A,U=k)}return T},vt=async(s,f,x,y,T,U,A)=>{const k=Array.from(s.length>0?s:" ");let M=f,g=k[0]??" ",b=W(g,y),P=yt(g);const B=async()=>{if(g.length!==0){if(P){const H=Math.max(8,Math.round(f+U-M)),C=await Z(g,H,Math.round(T),Math.round(y),A);if(C){const N=await m.embedPng(C.bytes);D.drawImage(N,{x:M,y:x-Math.max(0,C.height-T),width:C.width,height:C.height}),M+=C.width;return}}D.drawText(g,{x:M,y:x,size:y,font:b}),M+=b.widthOfTextAtSize(g,y)}};for(let H=1;H<k.length;H+=1){const C=k[H],N=W(C,y),Y=yt(C);if(Y===P&&(Y||N===b)){g+=C;continue}await B(),g=C,b=N,P=Y}await B()},st=(s,f)=>{let x=0;for(const y of Array.from(s)){const T=W(y,f);try{x+=T.widthOfTextAtSize(y,f)}catch{x+=Math.max(2,f*.55)}}return x};let D=m.addPage(_),E=0;const I=new Set,Q=[],Ct=D.getWidth(),ct=D.getHeight();let v=ct-l.topBottomMargin;const lt=()=>{E>=0&&!I.has(E)&&v-l.topBottomMargin>ct*.85||(D=m.addPage(_),E+=1,v=D.getHeight()-l.topBottomMargin)},ht=()=>D.getHeight();for(const s of G){const f=Ot(s.kind,l.defaultFontSize),x=Math.max(10,Math.round(f*l.lineHeight)),y=Ct-l.leftRightMargin*2;if(s.kind==="blank"){v-=K(s.kind,l);continue}if(s.kind==="image"){const A=y,k=r.quality==="high"?180:r.quality==="min"?100:140,M=Math.max(68,Math.round(k*(l.defaultFontSize/it.defaultFontSize)));if(v=mt(v,l.topBottomMargin,l.topBottomMargin,M+K(s.kind,l),lt,ht),(ut=s.imageDataUrl)!=null&&ut.startsWith("data:image/"))try{const g=Gt(s.imageDataUrl);if(!g)throw new Error("Invalid image payload");const b=g.mimeType==="image/png"?await m.embedPng(g.bytes):await m.embedJpg(g.bytes);D.drawImage(b,{x:l.leftRightMargin,y:v-M,width:A,height:M}),I.add(E)}catch{const g=W(s.text);D.drawText("[Image]",{x:l.leftRightMargin,y:v-x,size:f,font:g}),I.add(E)}else{const g=W(s.text);D.drawText(s.text,{x:l.leftRightMargin,y:v-x,size:f,font:g}),I.add(E)}v-=M+K(s.kind,l);continue}let T;try{T=pt(s.text,r.searchablePdf)?xt(s.text,y,f):Jt(s.text,W(s.text,f),f,y)}catch{T=xt(s.text,y,f)}let U=!1;for(const A of T){let k=x,M=null;const g=A.length>0?A:" ";if(pt(g,r.searchablePdf)&&(M=await Z(g,Math.round(y),Math.round(x),Math.round(f),s.kind.startsWith("heading")),M&&(k=Math.max(x,M.height))),v=mt(v,l.topBottomMargin,l.topBottomMargin,k,lt,ht),M){const b=await m.embedPng(M.bytes);D.drawImage(b,{x:l.leftRightMargin,y:v-M.height,width:M.width,height:M.height}),I.add(E)}else{try{await vt(g,l.leftRightMargin,v-x,f,x,y,s.kind.startsWith("heading"))}catch{const B=await Z(g,Math.round(y),Math.round(x),Math.round(f),s.kind.startsWith("heading"));
6if(B){const H=await m.embedPng(B.bytes);D.drawImage(H,{x:l.leftRightMargin,y:v-B.height,width:B.width,height:B.height}),k=Math.max(k,B.height)}}I.add(E);const b=/https?:\/\/[^\s)]+/gi;let P=b.exec(g);for(;P;){const B=P[0],H=g.slice(0,P.index),C=l.leftRightMargin+st(H,f),N=Math.max(8,st(B,f));Zt({PDFArray:c,PDFName:u,PDFNumber:S,PDFString:p},m,D,{x:C,y:v-x-1,width:N,height:x+3},B),P=b.exec(g)}}if(s.headingLevel&&!U&&A.trim().length>0){const b=D;b.ref&&(Q.push({title:A.trim(),level:s.headingLevel,pageRef:b.ref}),U=!0)}v-=k}v-=K(s.kind,l)}if(Q.length>0){const s=m.insertPage(0,_),f=W("Table of Contents",18),x=W("Contents",11),y=b=>{const P=b.replace(/[^\x20-\x7E]/g,"");return P.trim().length>0?P:"Section"},T=l.leftRightMargin,U=s.getHeight()-l.topBottomMargin;try{s.drawText("Table of Contents",{x:T,y:U,size:18,font:f})}catch{s.drawText("Table of Contents",{x:T,y:U,size:18,font:L})}let A=U-30;const k=16,M=Math.max(1,Math.floor((s.getHeight()-l.topBottomMargin*2-40)/k)),g=Q.slice(0,M);for(const b of g){const P=(b.level-1)*14,B=b.title.length>110?`${b.title.slice(0,107)}...`:b.title;let H=B,C=0;try{s.drawText(H,{x:T+P,y:A,size:11,font:x}),C=x.widthOfTextAtSize(H,11)}catch{H=y(B),s.drawText(H,{x:T+P,y:A,size:11,font:L}),C=L.widthOfTextAtSize(H,11)}Xt({PDFArray:c,PDFName:u,PDFNumber:S},m,s,{x:T+P,y:A-2,width:C,height:k},b.pageRef),A-=k}}!I.has(E)&&m.getPageCount()>1&&m.removePage(E);const ft=await m.save({useObjectStreams:!1}),gt=new Uint8Array(ft.byteLength);return gt.set(ft),{blob:new Blob([gt],{type:"application/pdf"}),pageCount:m.getPageCount()}};let J=null;for(const l of Tt){const m=Nt(it,l),L=await At(m);if(J=L.blob,L.pageCount>=1)break}if(!J)throw new Error("Failed to render output PDF");const Ft=await te(J,r,o),Rt=await e.write(Ft);F.push(Rt.id);const kt=Math.round((d+1)/t.length*100);n==null||n(kt)}return{outputIds:F}}const re=async t=>ee(t,Pt);export{re as run,ee as runWordToPdf};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.