October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

How to Add Headers and Page Numbers to Html2Pdf.app PDFs

Use Html2Pdf.app header and footer templates with pageNumber and totalPages spans, and reserve room with top or bottom margins.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

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

For an automated Html2Pdf.app PDF, add header or footer markup with headerTemplate or footerTemplate, put <span class="pageNumber"></span> where the current page should appear, and use <span class="totalPages"></span> for the total. Set enough top or bottom margin to make room. For a one-off conversion, the online converter provides interactive header and footer controls.

Choose the API or online converter

Workflow Best suited to What to expect
Online converter One-off or interactive conversions The converter offers 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, authenticate with an X-API-Key header, and handle the successful synchronous response as PDF bytes. See the API documentation.

For API automation, keep the API key on a server or another trusted backend. Do not put it in browser JavaScript or public source code.

As an Amazon Associate I earn from qualifying purchases.

Add page numbering through the API

1. Put placeholders in the template

Set headerTemplate for a header and footerTemplate for a footer. The documented dynamic-value classes are date, title, url, pageNumber, and totalPages. Use the last two in spans to display the current and total page counts.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
{
  "html": "<h1>Example report</h1>",
  "headerTemplate": "<div style="font-size:12px">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
}

This JSON illustrates the relevant fields. The margin values are example starting points in pixels, not universal settings; adjust them to the actual template height and page layout. Set the top margin for a header and the bottom margin for a footer. Insufficient space can leave a template with nowhere to display.

#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)

2. Style the template independently

Header and footer templates do not inherit CSS from the source page. Include needed styles directly in the template markup. External resources cannot load in templates; if a header or footer needs an image, embed it as a base64 data URL.

3. Send the request and save the PDF as bytes

Send the options as JSON in a POST body to the documented endpoint, include your key in X-API-Key, check the HTTP status, and write the successful response body directly to a PDF file. A minimal Python example:

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
import requests

api_key = "YOUR_API_KEY"
payload = {
    "html": "<h1>Example report</h1>",
    "headerTemplate": "<div style="font-size:12px">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,
}

response = requests.post(
    "https://api.html2pdf.app/v1/generate",
    headers={"X-API-Key": api_key},
    json=payload,
    timeout=90,
)
response.raise_for_status()
with open("report.pdf", "wb") as pdf_file:
    pdf_file.write(response.content)

Use the HTML or public-URL input appropriate to your workflow, as described in the API documentation. If your implementation uses a URL, the rendering service must be able to access that page and its required assets.

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

Fix missing headers, page numbers, or styling

  • The header or footer is absent: Increase marginTop or marginBottom to reserve room for it. These values are documented in pixels; the right amount depends on the template height and layout.
  • Page counts are blank: Confirm the markup uses the exact classes pageNumber and totalPages, each inside a span.
  • Template styling differs from the page: Add the required CSS inline in the header or footer template; styles from the source page are not inherited.
  • A template image does not appear: Embed the image as a base64 data URL rather than relying on an external resource.
  • The PDF is blank or missing page styles: Check that the source URL is public and that the rendering service can reach its CSS, fonts, images, and other required resources.
  • Your code gets an error or corrupt output: Check the HTTP status before saving the response. On success, save the response body as binary bytes, not JSON or text. Confirm the endpoint, POST body, and X-API-Key header against the API documentation.

Or skip the browser setup

If your actual goal is to capture a website as an image or PDF rather than generate a document with Html2Pdf.app, ScreenshotNeo is a website screenshot API and MCP server for developers. For example, this cURL request returns a screenshot of a page:

Rank #3
Sale
Canon imageCLASS LBP6030w - Monochrome Single-Function Wireless Compact Wireless Laser Printer, 1 Year Limited Warranty, 19 PPM, White - Print Only
  • FAST PRINT SPEEDS: Print up to 19 pages per minute.
  • COMPACT DESIGN: Space-saving, compact design fits anywhere in your home, school or small office.
  • WIRELESS CONNECTIVITY: Print from almost anywhere in your workspace using your compatible mobile device.
  • PAPER CAPACITY: Up to 150 sheets.
  • SUSTAINABILITY: Uses less than 2 watts in Energy Saver mode.
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 API options. It accepts cookie or consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; those steps can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and responses identify the page verdict and billing status in headers. Its MCP server offers take_screenshot, get_page_info, and capture_pdf for AI agents. The Free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots.

Sign up for ScreenshotNeo free to get 1,000 screenshots a month with no card.

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

Frequently Asked Questions

Can I put page numbers in the header instead of the footer?

Yes. Use the page-number spans in whichever template you set: headerTemplate or footerTemplate.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Brother HL-L2460DW Wireless Compact Monochrome Laser Printer with Duplex, Mobile Printing, Black & White Output | Includes Refresh Subscription Trial(1), Works with Alexa
  • BEST FOR HOME OFFICES & SMALL TEAMS – Engineered for consistent, premium print quality, the Brother HL-L2460DW Monochrome (Black & White) Laser Printer produces documents that are clear, crisp, and easy to review and share, all at an affordable price
  • COMPACT, CONNECTED, EXCEPTIONALLY EFFICIENT– Connect with built-in dual-band wireless (2.4GHz/5GHz), Ethernet, or to a single computer via USB interface. Prints at speeds up to 36ppm(2), plus automatic duplex printing saves time and reduces paper waste
  • BROTHER MOBILE CONNECT APP – Manage your wireless 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 – Tackle high-volume black & white printing with the 250-sheet capacity paper tray.(4) The manual feed slot enables printing on envelopes and specialty paper
  • 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

Can I use the source page’s stylesheet in a template?

No. Template CSS is separate; include its styles in the template markup.

Best Value
HP LaserJet M110w | Monochrome | Laser Printer | Fast Black-and-White Printing | Mobile Printing | Wireless Printing | Fast Printing
  • 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

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

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

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.