1import{r,u as A,j as e,L as C}from"./index-j7I9Tmll.js";import{P as k}from"./PdfPagePreview-or-1mmoF.js";import{P as W,S as B,r as E}from"./PDFButton-D40prZLX.js";import{i as U,M}from"./pdfEditor-C_FHqbws.js";import"./pdf.worker.min-DT7iqwIP.js";import"./browser-cLhBeQPl.js";function _(){const[i,j]=r.useState(null),[s,y]=r.useState("bottom-center"),[d,P]=r.useState(1),[c,m]=r.useState(!1),[S,f]=r.useState("Choose a PDF."),[h,l]=r.useState(""),[n,p]=r.useState(null);r.useEffect(()=>{p(null),l(""),i&&f("Source or settings changed. Create a new output.")},[i,s,d]),r.useEffect(()=>()=>{n!=null&&n.startsWith("blob:")&&URL.revokeObjectURL(n)},[n]),A({title:"Add Page Numbers to PDF Online Free | Kernel Tools",description:"Add page numbers to PDF files in your browser.",keywords:["add page numbers pdf","number pdf pages","pdf page numbering"],structuredData:{"@context":"https://schema.org","@type":"SoftwareApplication",name:"Add Page Numbers to PDF",applicationCategory:"UtilitiesApplication",operatingSystem:"Web",url:"https://kerneltools.dev/add-page-numbers-to-pdf",offers:{"@type":"Offer",price:"0",priceCurrency:"USD"}}});async function v(){try{m(!0),p(null),l("");const t=await W.load(new Uint8Array(await i.arrayBuffer()),{updateMetadata:!1}),a=await t.embedFont(B.Helvetica);
1t.getPages().forEach((u,w)=>{const b=u.getWidth(),N=u.getHeight(),g=String(d+w),x=a.widthOfTextAtSize(g,10),D=s.endsWith("center")?(b-x)/2:s.endsWith("right")?b-36-x:36,F=s.startsWith("top")?N-28:24;u.drawText(g,{x:D,y:F,size:10,font:a,color:E(.2,.2,.2)})});const o=await t.save({updateMetadata:!1});p(URL.createObjectURL(new Blob([o],{type:"application/pdf"}))),f("Numbered PDF ready.")}catch(t){l(t.message||"Could not add page numbers.")}finally{m(!1)}}return e.jsxs("div",{className:"pdf-tools-page",children:[e.jsx(C,{className:"pdf-tools-back",to:"/pdf-tools",children:"â All PDF tools"}),e.jsxs("header",{className:"pdf-tools-heading",children:[e.jsx("h1",{children:"Add Page Numbers to PDF"}),e.jsx("p",{children:"Number every page in your browser."})]}),e.jsxs("section",{className:"pdf-tool-workspace pdf-placement-desk",children:[e.jsxs("fieldset",{className:"pdf-desk-controls",disabled:c,children:[e.jsx("legend",{children:"Document and settings"}),e.jsx("input",{hidden:!0,type:"file",accept:"application/pdf,.pdf",onChange:t=>{var o;const a=(o=t.target.files)==null?void 0:o[0];if(!a||!U(a)||a.size>M)return l("Choose a PDF up to 100 MB.");j(a),l("")}}),e.jsx("button",{className:"btn btn-primary",onClick:t=>t.currentTarget.previousSibling.click(),children:"Choose PDF"}),e.jsxs("label",{children:["Position ",e.jsxs("select",{value:s,onChange:t=>y(t.target.value),children:[e.jsx("option",{value:"bottom-left",children:"Bottom left"}),e.jsx("option",{value:"bottom-center",children:"Bottom center"}),e.jsx("option",{value:"bottom-right",children:"Bottom right"}),e.jsx("option",{value:"top-center",children:"Top center"})]})]}),e.jsxs("label",{children:["Start number ",e.jsx("input",{type:"number",min:"1",value:d,onChange:t=>P(Math.max(1,Math.trunc(Number(t.target.value)||1)))})]}),i&&e.jsx("button",{className:"btn btn-primary",disabled:c,onClick:v,children:"Add page numbers"}),n&&e.jsx("a",{className:"btn btn-primary",href:n,download:"numbered.pdf",children:"Download PDF"}),e.jsx("p",{role:"status",children:S}),h&&e.jsx("p",{className:"pdf-tool-error",children:h})]}),e.jsx(k,{file:i,disabled:c,title:"Number placement",children:({width:t,height:a,number:o})=>e.jsx("svg",{className:"pdf-page-overlay",viewBox:`0 0 ${t} ${a}`,"aria-hidden":"true",children:e.jsx("text",{x:s.endsWith("center")?t/2:s.endsWith("right")?t-36:36,y:s.startsWith("top")?28:a-24,textAnchor:s.endsWith("center")?"middle":s.endsWith("right")?"end":"start",fontSize:"10",fill:"#333",children:d+o-1})})})]})]})}export{_ 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.