Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To add a header or page numbers to an Html2Pdf.app PDF, pass HTML in the API’s headerTemplate or footerTemplate fields, then reserve enough space with marginTop or marginBottom. Use pageNumber and totalPages spans for numbering. For a one-off conversion, the online converter also provides header and footer controls.

Choose the API or online converter

Workflow Best for What you need to know
Online converter One-off or interactive conversion The converter provides header and footer controls and is presented as a free demo without an API key. Html2Pdf.app online converter
API Repeated or application-driven PDF generation Send a POST request to https://api.html2pdf.app/v1/generate with an X-API-Key header. A successful synchronous response contains PDF binary data. API documentation

The steps and code below are for automated API use. Keep the API key in a server-side environment or another trusted backend location; do not expose it in browser JavaScript or public code.

Add a header, footer, and page count

  1. Put the markup for the top of each page in headerTemplate, and/or the markup for the bottom in footerTemplate.

  2. Use spans with the classes pageNumber and totalPages where the current page and total page count should appear. The supported dynamic template classes also include date, title, and url.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
    #1 Best Overall
    Brother DCP-L2640DW Wireless Compact Monochrome Multi-Function Printer, Copy, Scan, Duplex, Mobile Printing
    • BEST FOR SMALL BUSINESSES – Engineered for extraordinary productivity, the Brother DCP-L2640DW Monochrome (Black & White) 3-in-1 combines laser printer, scanner, copier in one compact footprint and delivers high-quality black & white prints
    • FAST PRINTER WITH EFFICIENT SCANNING – Produces documents quickly with print speeds up to 36 ppm(2) and scan speeds up to 23.6/7.9 ipm(3) (black/color). A 50-page auto document feeder(4) allows for convenient, time saving multi-page scanning and copying
    • FLEXIBLE CONNECTION OPTIONS – Easily navigate the changing demands of your business with secure multi-device connectivity via built-in dual-band wireless (2.4GHz / 5GHz) and Ethernet. Or connect locally to a single computer via USB interface
    • BROTHER MOBILE CONNECT APP – Print, scan, and manage your wireless printer anytime, from almost anywhere from your mobile device. Order Brother Genuine Supplies, track toner usage, and complete more work on-the-go(5)
    • CHOOSE BROTHER GENUINE TONER – When it’s time to replace your toner, be sure to choose Brother Genuine TN830 or TN830XL replacement toner. And with Refresh EZ Print Subscription Service, you’ll never worry about running out of toner again and you’ll enjoy savings of up to 50%(6) on Brother Genuine Toner. Get started with Refresh today with a Free Trial(1)
  3. Set marginTop and/or marginBottom to leave space for the relevant template. These values are in pixels. The values in the example below are illustrative starting points, not universal settings; adjust them to the height of your header or footer and your page layout.

  4. Style the template within its own markup. Header and footer templates do not inherit CSS from the source page. External resources cannot load inside templates, so embed any required image as a base64 data URL.

Minimal request body

{
  "html": "<h1>Example report</h1>",
  "headerTemplate": "<div style="font-size: 12px; text-align: center;">Example report</div>",
  "footerTemplate": "<div style="font-size: 12px; text-align: center;">Page <span class="pageNumber"></span> of <span class="totalPages"></span></div>",
  "marginTop": 40,
  "marginBottom": 40
}

The margin numbers are examples only. Increase them if the template is clipped or overlaps page content; reduce them if the reserved area is unnecessarily large.

Rank #2
Brother HL-L2405W Wireless Compact Monochrome Laser Printer with Mobile Printing, Black & White Output | Includes Refresh Subscription Trial(1), Works with Alexa
  • BEST FOR HOMES & HOME OFFICES – Engineered for consistent, premium print quality, the Brother HL-L2405W Monochrome (Black & White) Laser Printer delivers sharp, crisp prints at an affordable price. Prints one-sided documents at speeds up to 30ppm(2)
  • COMPACT, CONNECTED PRINTER – Flexible connection options make this an ideal printer for home use and at-home offices. Securely connect to multiple devices with built-in dual-band wireless (2.4GHz/5GHz) or locally to a single computer via USB interface
  • BROTHER MOBILE CONNECT APP – Manage your printer remotely and print from your mobile device anytime, from almost anywhere. Order Brother Genuine Supplies, track toner usage, and complete more work on-the-go(3)
  • VERSATILE PAPER HANDLING – Enjoy seamless, reliable everyday printing with the 250-sheet paper tray(4) and a manual feed slot that enables printing on envelopes and specialty pape
  • BROTHER IS AT YOUR SIDE – Backed by Brother with a 1-year limited warranty and free online, call, or live chat support for the life of your printer

Send the API request and save the PDF

Here is a complete cURL example. Replace YOUR_API_KEY with a key held securely on your backend. The request body is JSON, and the response is written to a PDF file as binary data.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -X POST "https://api.html2pdf.app/v1/generate" 
  -H "X-API-Key: YOUR_API_KEY" 
  -H "Content-Type: application/json" 
  --data '{"html":"<h1>Example report</h1>","headerTemplate":"<div style="font-size: 12px; text-align: center;">Example report</div>","footerTemplate":"<div style="font-size: 12px; text-align: center;">Page <span class="pageNumber"></span> of <span class="totalPages"></span></div>","marginTop":40,"marginBottom":40}' 
  --output report.pdf

For application code, follow the official API documentation for request parameters and authentication. Check the HTTP status before treating the response as a completed PDF, and handle successful response content as bytes—not JSON or text.

Check the rendered result

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshooting common problems

Header or footer is missing or cut off

The reserved top or bottom margin may be too small for the template. Increase marginTop for a header or marginBottom for a footer, then regenerate and inspect the layout.

Page numbers do not appear

Check that the template uses the exact class names pageNumber and totalPages on span elements. The page number and page count are inserted dynamically; ordinary text such as “Page 1 of 4” will not update automatically.

Template styles or images are missing

Template CSS does not inherit from the source page, and external resources cannot load in a header or footer template. Include the necessary styles inline in the template and embed images as base64 data URLs.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
HP LaserJet M110w Wireless Black & White Printer, Print, Fast speeds, Easy Setup, Mobile Printing, Best-for-Small Teams
  • FROM AMERICA'S MOST TRUSTED PRINTER BRAND – Perfect for small teams printing professional-quality black & white documents and reports. Perfect for 1-3 people
  • WORLD'S SMALLEST LASER IN ITS CLASS – Precision laser printing that fits anywhere
  • FAST PRINT SPEEDS – Up to 21 black-and-white pages per minute single-sided
  • WIRELESS WITH SELF-RESET – Helps you stay connected
  • PRINT FROM ANY DEVICE – Wireless printing from any mobile device, PC or tablet. Works with Microsoft, Mac, AirPrint, Android, Chromebook and more

The generated PDF is blank or lacks page styles

Check that the submitted HTML or source URL is valid and that linked CSS, fonts, images, and other resources are publicly reachable by the rendering service. The official Python example also demonstrates the API request pattern.

The client cannot parse the response

A successful synchronous API response is PDF binary data, not a JSON object or text document. Check the HTTP status and write the response body to a file or binary stream without decoding it as text.

Or skip the browser setup

If your actual need is a clean screenshot of a web page rather than a paginated PDF with a custom header or footer, ScreenshotNeo can return a PNG, JPEG, WebP, or PDF from one GET request. It accepts cookie banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing, and response headers identify the page verdict and billing status. ScreenshotNeo also has an MCP server for AI agents, including Claude, Cursor, and other MCP clients.

Example cURL request, using a page URL and API key:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo documentation for options and setup. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots. Sign up for free ScreenshotNeo access.

Frequently Asked Questions

Can Html2Pdf.app number pages without a custom header or footer?

The documented page-count placeholders are used inside header or footer templates. Place the relevant span in one of those templates to display numbering.

Can I use the source page’s stylesheet to style the header template?

No. Header and footer templates do not inherit the source page’s CSS; include the styles the template needs in its own markup.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.