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

Set a single explicit --margin-top value in physical units, and tune --header-spacing separately. The first reserves space at the top of every page; the second controls the gap between a repeated header and the document content. Also remove unintended CSS margins and make the header’s height predictable—otherwise a global page margin alone may not produce a consistent content start.

Set a global top margin and separate header spacing

For a document with a repeated HTML header, start with one page-level margin and an explicit header gap:

wkhtmltopdf 
  --margin-top 25mm 
  --header-spacing 0 
  --header-html header.html 
  input.html output.pdf

--margin-top reserves the top inset on the page. --header-spacing is the gap between the header and the content; it is not another way to set the page margin. The command-line option is measured in millimetres, and its documented default is 0. The corresponding library settings are margin.top and header.spacing.

Use a physical unit such as mm, cm, or in rather than relying on CSS pixels. With no header, set the page margin and reset document margins. With a header, measure its rendered height and allow enough room for the header plus the desired gap. For example, an 18 mm header and a 2 mm content gap suggest starting with a 20 mm top margin, then adding a small allowance if font rendering, borders, or line wrapping could make the header taller.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Epson EcoTank ET-2800 Wireless Color All-in-One Supertank Printer - Black
  • INNOVATIVE CARTRIDGE-FREE PRINTING — No more dealing with lots of tiny ink cartridges; With this wireless document and photo printer each ink bottle set is equivalent to about 90 individual cartridges²
  • LESS FREQUENT INK REPLACEMENT — Replacement ink bottles don't have to be changed nearly as often as ink cartridges¹; When you choose this combination printer, scanner and copier you can print up to 4,500 pages black/7,500 color³
  • COLOR PRINTING — Up to 2 years of ink in the box4 (and with every replacement ink set) for fewer out-of-ink frustrations
  • ZERO CARTRIDGE WASTE — By using an Epson EcoTank printer you can help reduce the amount of cartridge waste ending up in landfills
  • HOME PRINTER DESIGNED FOR RELIABILITY — The Epson EcoTank ET-2800 All-in-One Supertank Color Printer creates vivid, detailed prints and documents thanks to Micro Piezo Heat-Free Technology; Fire off 10 ISO pages per minute1 to easily finish large jobs

The header and content must fit within the reserved area. If the header is clipped or overlaps content, increasing --header-spacing alone may make the problem worse: the header can be pushed outside the page. Adjust --margin-top to give the header and gap sufficient room.

Reset the header document’s default spacing

A separate header HTML file can have its own browser-default body margin. Remove it so it does not introduce an unexpected offset:

<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <style>
    html, body {
      margin: 0;
      padding: 0;
    }
    .header {
      height: 18mm;
    }
  </style>
</head>
<body>
  <div class="header">Invoice report</div>
</body>
</html>

The explicit height here is illustrative: set it to the size your actual header needs, and check the rendered result. If its text wraps or an image loads at a different size, the visible header can grow despite a fixed starting margin. Keep content width, font, line-height, borders, and image dimensions stable where a repeatable header height matters.

Rank #2
Sale
Epson EcoTank Photo ET-8550 Wireless Wide-Format All-in-One Tank Printer
  • CARTRIDGE-FREE PRINTING — Print lab-quality photos, graphics and creative projects; Get vibrant colors and sharp text with Epson's high-accuracy printhead and Claria ET Premium 6-color inks
  • INK BOTTLES — Save on photos1 and creative projects with affordable in-house printing; All-in-one printer allows you to print 4" x 6" photos for about 4 cents each vs. 40 cents with traditional ink cartridges1
  • LESS FREQUENT INK REPLACEMENT — Replacement ink bottles don't have to be changed nearly as often as ink cartridges¹; Printer, scanner and copier lets you print up to 6,200 color pages³
  • PRINT FOR LONGER — Up to 2 years of ink in the box² (and with every replacement ink set) for fewer out-of-ink frustrations with this wireless printer
  • ZERO CARTRIDGE WASTE — Epson EcoTank printer helps reduce the amount of cartridge waste ending up in landfills; Cartridge-free printer uses high-yield ink bottles; Each replacement ink bottle set is equivalent to about 100 individual ink cartridges⁴

Remove competing margins in the main document

CSS margins on html, body, headings, or the first content wrapper can add space on top of the page-level inset. Temporarily clear them while diagnosing the layout, then add back only spacing that serves a specific purpose:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
html, body {
  margin: 0;
  padding: 0;
}

.content {
  margin-top: 0;
  padding-top: 0;
}

Inspect the first element inside the document as well as the body. A heading’s top margin or a wrapper’s padding can make the first page appear to have a larger margin even though later pages begin at the expected position. Keep intentional spacing in one known place rather than stacking page margin, body margin, and first-child margin.

Choose between command-line margins and CSS @page

For one HTML document without a separately injected wkhtmltopdf header, CSS paged-media rules can set the page-box margins:

Rank #3
HP Smart Tank 5000 Wireless All-in-One Ink Tank Printer, Scanner, Copier with 2 Years of Ink Included, Best-for-Home, Cartridge-Free, Refillable and AI-Enabled. (5D1B6A)
  • SET IT UP ONCE AND PRINT WITH CONFIDENCE. No complicated maintenance. Just easy, reliable printing you can count on.
  • INK FOR YEARS. NOT MONTHS. Up to 2 years of ink included. Get thousands of pages of cartridge-free printing. More pages, less hassle
  • KEEPS PRINTING WELL AFTER COMPETITORS HAVE QUIT. No complex maintenance. Sharper text, richer colors.[2] Only with HP Smart Tank
  • PREMIUM SUPPORT - Strong technical expertise to solve issues faster
  • THE LAST PRINTER YOU'LL EVER NEED. Enjoy years of refillable, cartridge-free printing.
@page {
  size: A4;
  margin-top: 25mm;
  margin-right: 15mm;
  margin-bottom: 20mm;
  margin-left: 15mm;
}

html, body {
  margin: 0;
  padding: 0;
}

CSS 2.2 defines page margins inside an @page rule and gives @page { margin: 3cm; } as an all-page example. In a wkhtmltopdf workflow with a repeated HTML header, the CLI margin is generally easier to reason about: the header is injected as a separate document and has its own spacing setting. Avoid setting the same intended inset independently in CSS and on the command line unless you have verified how your particular input and build combine them.

Approach Use it when What to watch
--margin-top with optional --header-spacing You need a page-level inset, especially with a repeated wkhtmltopdf HTML header. Header height and spacing both need room inside the page layout.
CSS @page margins You are styling page margins in a single HTML document without a separately injected header. Reset document margins and avoid unintended extra CSS spacing.

Keep multiple pages and page objects consistent

With one input document and one global margin, the top inset is the same setting throughout the render. Differences in where content appears can still result from changing header dimensions, CSS margins, or page geometry. A separate issue arises when a command contains multiple page objects with different or missing headers. A wkhtmltopdf issue report for version 0.12.2.1 describes pages using the tallest header’s top-margin value even where another page has no header. That report is historical evidence for a particular scenario, not a guarantee that every build behaves identically.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • If page objects share one PDF, give their headers the same dimensions and use a consistent header setup.
  • If headers need materially different heights, consider rendering separate PDFs and merging them with a downstream PDF tool.
  • Check page size and orientation as well as margins. A4 is the documented default; --page-size, --page-height, and --page-width can change the available content area and pagination even when --margin-top stays the same.

Verify the result with a repeatable fixture

  1. Run wkhtmltopdf --version and record the binary/build used to generate the PDF. wkhtmltopdf behavior and available options can depend on the build; do not assume a different machine uses the same one.
  2. Temporarily remove top margins and padding from html, body, headings, and the first content wrapper.
  3. Set one explicit CLI --margin-top with a physical unit, and set --header-spacing 0 as a baseline if using an HTML header.
  4. Zero the header body’s margin and padding. Make header text, fonts, borders, and image dimensions stable.
  5. Generate a fixture long enough to span several pages. Add a visible horizontal rule at the intended content start, then compare pages 1, 2, and the last page.
  6. Once the content start is stable, add back only the needed header gap or CSS spacing, changing one value at a time.

Troubleshoot the common causes of drift

Symptom Likely cause Fix
Every page starts too low. The global top margin is larger than needed, or header spacing and CSS margins are adding to the inset. Keep the page margin as the single page-level control; reset document and first-content margins, then set only the required header gap.
The header is clipped, missing, or too close to the page edge. There is not enough top-margin room for the header and its spacing, or the header body has default spacing. Zero the header body margin and padding, check the header’s rendered height, and increase --margin-top enough to accommodate it.
The first page differs from later pages. The first content element has a top margin or the document’s first-page content is laid out differently from the repeated pages. Reset the first element and wrapper margins, then inspect the marked content start on each page.
Some pages differ when using multiple page objects. Objects may have different header heights or missing headers; an issue report describes tallest-header behavior in wkhtmltopdf 0.12.2.1. Standardize header dimensions across objects or render separate PDFs and merge them afterward.
Content wraps or pagination changes after changing paper setup. Page size or orientation changed the available page area. Set and verify the intended page size and orientation alongside the margin options.
A numeric margin seems ignored or inconsistent. The setting may be in a different place than expected, or another CSS inset may be stacking with it. Use an explicit unit such as 25mm, check the actual binary with wkhtmltopdf --version, and temporarily clear competing CSS margins.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If the goal is to capture a web page rather than configure a wkhtmltopdf installation, ScreenshotNeo is a website screenshot API that can return PNG, JPEG, WebP, or PDF. The request below captures a URL as WebP; it is an alternative for page capture, not a way to tune a wkhtmltopdf PDF’s page margins.

Rank #4
NDYIN Portable Printers Wireless for Travel, N80 Bluetooth Thermal Printer
  • Wireless Bluetooth Printer: Portable thermal printer compatible with iPhone, Android phones, iPad and tablet computers via Bluetooth. For smartphones, please download the "Nada Print" App. You can also connect to laptops and computers for printing using a USB-C cable. (Note: Laptops and computers can only be connected via USB and require the installation of a driver first. Bluetooth connection is not supported.)
  • No-ink printing: Only supports US Letter and A4 size thermal paper.(Doesn't support regular paper) The no-ink portable thermal printer uses direct thermal technology, requiring no ink, toner or ribbons, making it environmentally friendly, cost-effective and time-saving. The thermal printer package comes with a roll of US Letter thermal printing paper. Note: When installing the paper, remember to switch the paper size switch on APP
  • Clear Print: NDYIN N80 portable thermal printer adopts high-definition printing technology, with a 203DPI resolution to provide you with clear printing results. This mobile printer is compatible with roll paper, folded paper and tattoo transfer paper, supporting printing from your mobile phone PDF, Word, pictures and web pages anytime and anywhere. It is recommended to use our NDYIN thermal paper to achieve good printing quality
  • Portable wireless printer for travel: The thermal printer is equipped with a built-in 1500mAh rechargeable battery, which can print 160 sheets of 8.5" x 11" thermal paper after being fully charged. It weighs only 1.5 pounds and is compact in size. This ink-free portable printer can be easily carried in a backpack or briefcase! It is perfect for business travel, cars, small offices, construction sites, schools and homes. You can print documents, contracts, invoices and boarding passes anytime and anywhere
  • The N80 thermal printer has a wide range of uses. The package includes the N80 printer, a roll of US Letter paper(7m/roll), a user manual, a guide card, a type-C soft cable and a type C adapter. Note: The charging adapter is not included. Special thermal paper is required for use; ordinary paper cannot be used. This ink-free portable thermal printer is suitable for various scenarios such as home, school, travel, office, and outdoor, meeting the printing needs of different groups of people. This tattoo template printer is also compatible with tattoo transfer paper, making it an ideal choice for tattoo art

One GET request returns the capture. See the ScreenshotNeo API documentation for API options and output formats.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
  • Cookie and consent banners are accepted and removed before the shot; newsletter popups and chat widgets are removed too. Each cleanup step can be turned off.
  • Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed. Response headers report the page verdict and billing status.
  • An MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents and other MCP clients.
  • The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000. Every feature is available on every plan.

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

Frequently Asked Questions

Does --header-spacing 0 remove the repeated header?

No. It sets the gap between the header and content to zero; use --header-html to specify a header.

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.

Does this method guarantee identical pagination on every machine?

No. The procedure controls the page inset and reduces common layout differences, but you should verify the actual wkhtmltopdf build and rendered output used in your environment.

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.