Use CSS page regions in an @page rule: put repeating content in @top or @bottom, use counter(page) for the current page and counter(pages) for the document total, and reserve enough margin for the content. For richer headers and footers, move an HTML element into a named flow and reference that flow from the page region.
Add page numbers with CSS page regions
DocRaptor supports page-margin regions for content that belongs outside the main text area. This minimal rule prints the current and total page numbers in a footer:
As an Amazon Associate I earn from qualifying purchases.
@page {
margin-bottom: 36pt;
@bottom {
content: "Page " counter(page) " of " counter(pages);
}
}
The built-in page counter is the current page; pages is the total page count. For a number without surrounding text, use content: counter(page); inside @bottom. You can also format the current-page counter, for example with alphabetic numbering, or reset it for a later section. Treat a reset as a deliberate numbering choice and inspect the generated PDF, particularly if section numbering must differ from the total-document count.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Scan for outdated or missing drivers - takes under a minute3Repair Windows errors before they cause bigger problemsAdd a repeating text header or footer
Put fixed text directly in the page region. The same approach works at the top and bottom of each page:
#1 Best Overall
- Create and edit PDFs. Collaborate with ease. E-sign documents and collect signatures. Get everything done in one app, wherever you go.
- Edit text and images without jumping to another app.
- E-sign documents or request e-signatures on any device. Recipients don’t need to log in to e-sign.
- Convert PDFs to editable Microsoft Word, Excel, or PowerPoint documents.
- Share PDFs for collaboration. Commenting features make it easy for reviewers to comment, mark up, and annotate.
@page {
margin-top: 48pt;
margin-bottom: 36pt;
@top {
content: "Quarterly report";
}
@bottom {
content: "Page " counter(page) " of " counter(pages);
}
}
For a running header that changes with document content, DocRaptor’s documented approach is to set a CSS string on a chapter heading with string-set, then use string(chapter-title) as the page-region content. This is useful when the header should reflect the current chapter rather than repeat one fixed label.
Use HTML for a formatted header or footer
When the region needs richer markup than a text string, move an HTML element into a named static flow with the CSS flow property, then place that flow in the page region. Put the flow element near the beginning of the HTML document: if the parser encounters footer markup only after a long body, earlier pages may not receive it.
Rank #2
- Create and edit PDFs. Collaborate with ease. E-sign documents and collect signatures. Get everything done in one app, wherever you go.
- Edit text and images without jumping to another app.
- E-sign documents or request e-signatures on any device. Recipients don’t need to log in to e-sign.
- Convert PDFs to editable Microsoft Word, Excel, or PowerPoint documents.
- Share PDFs for collaboration. Commenting features make it easy for reviewers to comment, mark up, and annotate.
<body>
<style>
footer { flow: static(footer-html); }
@page {
margin-bottom: 60pt;
@bottom { content: flow(footer-html); }
}
</style>
<footer>
<strong>Company name</strong>
<span>Page information or other footer content</span>
</footer>
<main>
<!-- regular document content -->
</main>
</body>
Style the elements in the flow with ordinary CSS for typography and alignment. For a header, use the analogous @top region. Size the reserved margin for the tallest version the content can render; margins do not automatically grow to fit the header or footer.
Recommended Free Tools
Give title pages and sections different layouts
Use named pages when some pages need different margin content. Assign a page name with the CSS page property, then define a matching @page rule:
Rank #3
- Perfect Adobe Acrobat Pro alternative – lifetime license for Windows 10 and 11.
- EDIT text, images, pages, hyperlinks, designs in PDF documents. ORGANIZE PDFs.
- READ and Comment on PDFs – Intuitive reading modes & document commenting and mark up tools!
- CREATE, COMBINE, SCAN and COMPRESS PDFs.
- FILL forms & Digitally Sign PDFs. Work with Digital certificates
#title-page { page: title; }
.chapter { page: chapter; }
@page title {
@top { content: ""; }
@bottom { content: ""; }
}
@page chapter {
margin-top: 44pt;
margin-bottom: 36pt;
@top { content: "Chapter guide"; }
@bottom { content: "Page " counter(page) " of " counter(pages); }
}
A change in page name inserts a page break. Named pages control styling; they do not, by themselves, decide whether numbering restarts. If numbering should restart for a section, apply a counter reset intentionally and verify the result in the PDF. If it should continue through title and chapter pages, check that the generated sequence does so.
Set margins and check for clipping
Page-region content sits in the page margin, not in the main text flow. Define top or bottom margins large enough for the rendered region; otherwise it can be clipped or hidden. DocRaptor’s margins guide reports a default page margin of 0.75in, but do not assume that default is sufficient for a designed header or footer. Set the required margins explicitly.
Rank #4
- EDIT text, images & designs in PDF documents. ORGANIZE PDFs. Convert PDFs to Word, Excel & ePub.
- READ and Comment PDFs – Intuitive reading modes & document commenting and mark up.
- CREATE, COMBINE, SCAN and COMPRESS PDFs
- FILL forms & Digitally Sign PDFs. PROTECT and Encrypt PDFs
- LIFETIME License for 1 Windows PC or Laptop. 5GB MobiDrive Cloud Storage Included.
- Check the first and last pages, named-page transitions, and pages with the longest header or footer.
- Look for clipping and confirm that the reduced content area has not caused unwanted pagination changes.
- If an existing document began clipping after a Prince 12 upgrade, review its margins: the migration note says page-margin content can no longer overflow beyond the margin area as it did before Prince 12.
Generate the PDF and verify the result
DocRaptor’s API overview describes sending a JSON POST to https://api.docraptor.com/docs. A minimal PDF request supplies the PDF type and document content; successful synchronous generation returns PDF bytes for the caller to save or deliver. The response includes X-DocRaptor-Num-Pages, which reports the generated PDF’s page count. That header is useful for checking document size, but it cannot confirm whether page regions look right. Inspect the actual PDF, including the first and last pages and any title or section layouts.
The DocRaptor tutorial includes cURL and language samples and notes that test mode produces watermarked documents. Use its current API documentation for the request schema and credentials rather than guessing request fields.
Best Value
- Full-featured PDF Editor: Edit text in the document
- Fully convert PDF to Word and Excel and continue editing
- NEW: Further development of existing functions
- NEW: Even faster and more user-friendly
- NEW: Over 75 small improvements in all areas
Choose page regions when the renderer supports them
Page regions are a CSS Paged Media technique. DocRaptor’s documentation notes that browser-based HTML-to-PDF libraries such as Puppeteer have not adopted these specifications, and identifies DocRaptor, Prince, and a few other commercial PDF generators as supporting the page-region concept. If your implementation depends on repeating margin content, verify that the PDF engine you use supports the required region behavior; this distinction alone does not establish that one generator is better overall.
Troubleshooting
- The header or footer is missing or clipped: Increase the corresponding page margin, then inspect the rendered PDF. The margin does not automatically resize to fit region content.
- Only later pages show the HTML footer: Move the flow element near the beginning of the HTML document so it is available before earlier pages are laid out.
- The total-page label is wrong or absent: Check that the page-region content uses the predefined
counter(pages)spelling and inspect the generated PDF rather than relying only on the API page-count header. - Numbering restarts unexpectedly or does not restart: Review any
counter-resetapplied to the target section and distinguish section numbering from total-document numbering. - A title page unexpectedly uses chapter styling: Check the element’s assigned
pagename and the matching named@pagerule; a page-name change also inserts a page break. - Layout changed after a renderer upgrade: Recheck margin dimensions, especially if the document previously relied on page-region content overflowing into the page body.
Or skip the browser setup
ScreenshotNeo is a website screenshot API, not a PDF generator, so it does not add DocRaptor page numbers or headers. If your separate goal is to capture a webpage as an image, one GET request returns a screenshot; see the ScreenshotNeo API documentation.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
ScreenshotNeo removes cookie banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, and failed loads are never billed. Its MCP server lets AI agents take screenshots. The Free plan includes 1,000 shots a month with no card, and paid plans start at $5 for 3,000. Every feature is on every plan. Learn more at ScreenshotNeo, or sign up free for 1,000 screenshots a month with no card.
Frequently asked questions
Can I use these CSS page regions with every HTML-to-PDF library?
No. DocRaptor describes page regions as CSS Paged Media functionality and notes that browser-based libraries such as Puppeteer have not adopted those specifications. Confirm support in the renderer you plan to use.
Does the API page-count header prove that the footer rendered correctly?
No. X-DocRaptor-Num-Pages reports the generated PDF’s page count; visual inspection is still needed to verify the page regions and their layout.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




