Add page numbers to PDF
Unlike Microsoft Word, PDFs do not have a magical "Page Number" setting that you can just toggle on.
A PDF is a finalized layout format. A page number is just a piece of text that happens to be drawn at the exact same coordinate on every page. To add page numbers, we have to explicitly draw text onto each page's canvas.
Every page in a PDF has a Content Stream—a sequence of instructions telling the renderer how to draw paths, images, and text.
When you use this tool, our WebAssembly engine loops through every page in the document. For each page, it calculates the desired X and Y coordinates (e.g., bottom-center), and appends a new set of text-drawing instructions to the end of that page's Content Stream.
To draw text, the PDF must have access to the font. If we used a custom font for the page numbers, we would have to embed that entire font file into the PDF, inflating the file size.
Instead, this tool uses standard base fonts (like Helvetica) that are guaranteed to be supported by all PDF viewers, ensuring the file size remains small and the text renders perfectly everywhere.
How does this tool add page numbers to the document?