1import{r as c,u as D,j as e,L as v}from"./index-j7I9Tmll.js";import{getDocument as C,GlobalWorkerOptions as N}from"./pdf-TtSH7s3_.js";import{p as S}from"./pdf.worker.min-DT7iqwIP.js";import{i as k,M as T,a as A}from"./pdfEditor-C_FHqbws.js";N.workerSrc=S;function E(n,m){const o=n.split(/\s+/).filter(Boolean).slice(0,3e3),p=m.split(/\s+/).filter(Boolean).slice(0,3e3),g=o.filter(i=>!p.includes(i)),h=p.filter(i=>!o.includes(i));return{removed:g,added:h}}function R(){const[n,m]=c.useState([null,null]),[o,p]=c.useState(!1),[g,h]=c.useState("Choose two PDFs to compare."),[i,f]=c.useState(""),[t,u]=c.useState(null),[l,x]=c.useState(1);D({title:"Compare PDF Text Online Free | Kernel Tools",description:"Compare the extracted text and structure of two PDFs.",keywords:["semantic pdf comparison","pdf text diff","compare pdf text"],structuredData:{"@context":"https://schema.org","@type":"SoftwareApplication",name:"Semantic PDF Compare",applicationCategory:"UtilitiesApplication",operatingSystem:"Web",url:"https://kerneltools.dev/compare-pdf",offers:{"@type":"Offer",price:"0",priceCurrency:"USD"}}});async function w(s){const a=await C({data:new Uint8Array(await s.arrayBuffer()),enableXfa:!1}).promise;if(a.numPages>A)throw new Error("This PDF exceeds the page limit.");const r=[];for(let d=1;d<=a.numPages;d++){const j=await(await a.getPage(d)).getTextContent();r.push(j.items.map(b=>b.str).join(" "))}return{pages:r,text:r.join(` 2`)}}async function y(){if(f(""),!n[0]||!n[1])return f("Choose both PDF files first.");try{p(!0),u(null),x(1);const[s,a]=await Promise.all(n.map(w)),r=E(s.text,a.text);u({left:s,right:a,diff:r}),h("Text comparison complete.")}catch(s){f(s.message||"Could not compare these PDFs.")}finally{p(!1)}}function P(s,a){var d;const r=(d=a.target.files)==null?void 0:d[0];if(!r||!k(r)||r.size>T)return f("Choose a PDF up to 100 MB.");m(j=>j.map((b,F)=>F===s?r:b)),f(""),u(null),h("Ready to compare.")}return e.jsxs("div",{className:"pdf-tools-page",children:[e.jsx(v,{className:"pdf-tools-back",to:"/pdf-tools",children:"â All PDF tools"}),e.jsxs("header",{className:"pdf-tools-heading",children:[e.jsx("h1",{children:"Compare PDF text"}),e.jsx("p",{children:"Find added and removed text between two PDFs."})]}),e.jsxs("section",{className:"pdf-tool-workspace pdf-comparison-desk",children:[e.jsxs("div",{className:"pdf-tool-grid",children:[e.jsxs("label",{children:["Original PDF",e.jsx("input",{type:"file",accept:"application/pdf,.pdf",disabled:o,onChange:s=>P(0,s)})]}),e.jsxs("label",{children:["Updated PDF",e.jsx("input",{type:"file",accept:"application/pdf,.pdf",disabled:o,onChange:s=>P(1,s)})]})]}),e.jsx("button",{className:"btn btn-primary",disabled:o,onClick:y,children:o?"Comparingâ¦":"Compare text"}),e.jsx("p",{role:"status",children:g}),i&&e.jsx("p",{className:"pdf-tool-error",children:i}),t&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"pdf-preview-navigation",children:[e.jsx("button",{className:"btn btn-ghost",disabled:l<=1,onClick:()=>x(l-1),children:"Previous page"}),e.jsxs("span",{children:["Page ",l," of ",Math.max(t.left.pages.length,t.right.pages.length)]}),e.jsx("button",{className:"btn btn-ghost",disabled:l>=Math.max(t.left.pages.length,t.right.pages.length),onClick:()=>x(l+1),children:"Next page"})]}),e.jsx("div",{className:"pdf-comparison-panes",children:[t.left,t.right].map((s,a)=>e.jsxs("section",{children:[e.jsx("h2",{children:a?"Updated":"Original"}),e.jsx("p",{children:n[a].name}),e.jsx("pre",{children:s.pages[l-1]??"No corresponding page in this document."})]},a))}),e.jsxs("section",{className:"pdf-merge-report",children:[e.jsx("h2",{children:t.diff.added.length||t.diff.removed.length?"Text changes found":"No word-presence differences found"}),e.jsxs("p",{children:[t.left.pages.length," pages versus ",t.right.pages.length," pages · ",t.diff.added.length," added tokens · ",t.diff.removed.length," removed tokens."]}),t.diff.added.length>0&&e.jsxs("p",{children:[e.jsx("strong",{children:"Added:"})," ",t.diff.added.slice(0,80).join(" ")]}),t.diff.removed.length>0&&e.jsxs("p",{children:[e.jsx("strong",{children:"Removed:"})," ",t.diff.removed.slice(0,80).join(" ")]}),e.jsx("p",{className:"pdf-tool-note",children:"Text is extracted with PDF.js in your browser. This compares word presence across the first 3,000 tokens. Word order, repetition, later text and visual layout changes may not be detected; use the page panes to review the extracted text."})]})]})]})]})}export{R as default};
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.