Overview
Page numbers are added to the footer of each page in your generated PDF, showing the current page and total page count (e.g., “Page: 1 of 42”).Enabling Page Numbers
When running repo2pdf, you’ll be prompted:How It Works
Page numbers are added in a two-phase process:Phase 1: Buffer All Pages
First, the PDF is generated with buffered pages:Phase 2: Add Page Numbers
After all content is rendered, repo2pdf loops through all pages and adds numbers: Fromclone.ts:132-151:
Page numbers are only added when generating a single PDF. When using
--one-pdf-per-file, page numbers are not added since each file becomes its own PDF.Page Number Format
The format is always:Page: 1 of 1(single page)Page: 1 of 42(first page of 42)Page: 42 of 42(last page)
Positioning and Alignment
Bottom Placement
Positioned at the bottom using the page height and margin:This places the text in the middle of the bottom margin area.
Visual Example
Buffered Pages Explained
Page buffering is essential for page numbers because:Why Buffering is Required
Why Buffering is Required
- Unknown Total: When generating the PDF, we don’t know the total page count until all content is processed
- Need to Revisit: We need to go back to each page to add “X of TOTAL”
- PDFKit Limitation: Without buffering, PDFKit streams pages immediately and they can’t be modified
WhenbufferPagesis true, pages are kept in memory and can be accessed viaswitchToPage()
switchToPage() Method
switchToPage() Method
The This is why page numbers can be added after all content is rendered.
switchToPage() method allows navigating back to any page:Text Flow Closure
Before adding page numbers, the text flow must be closed:Single PDF vs Multiple PDFs
The
onePdfPerFile option takes precedence. When enabled, page numbers are not added even if you select “Yes” for page numbers.Performance Impact
Memory Usage
Buffering pages keeps them in memory instead of streaming to disk. For very large repositories (1000+ files), this can use significant RAM.
Processing Time
Adding page numbers requires a second pass through all pages. This typically adds 10-20% to generation time.
Use Cases
- Documentation: “See page 42 for authentication logic”
- Printing: Easy reference when reviewing printed PDFs
- Navigation: Quickly estimate document size and location
- Professional Output: Makes PDFs look more polished and organized
Disabling Page Numbers
To generate PDFs without page numbers:Font and Style
Page numbers use the default PDF font with:- Position: Bottom center
- Alignment: Center
- Format: “Page: X of Y”