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

To reduce excess space above or below an HTML header in wkhtmltopdf, check three things: the header HTML’s rendered height and CSS margins, the gap set by --header-spacing, and the page’s reserved top margin set by --margin-top. Start with a compact header, set header spacing to zero, then give the top margin enough room for the header and any breathing space you want.

What controls whitespace around a wkhtmltopdf header?

Whitespace is not controlled by one setting. The visible result comes from the header document’s own layout, the gap between the header and the page content, and the space reserved at the top of each PDF page. Adjusting only one layer can leave a blank band in place—or cause the header to overlap, move out of the printable area, or disappear.

  • header.html determines how tall the rendered header is, including any margins or padding in its body and elements.
  • --header-spacing controls the distance between the header and the document content. The CLI reference specifies millimetres and a default of 0.
  • --margin-top reserves space at the top of the PDF page. The wkhtmltopdf settings documentation identifies this as the setting to adjust if a large header gap pushes the header outside the page.

The practical goal is not necessarily a zero top margin. It is a top margin that accommodates the header’s actual rendered height, plus only the separation you intend.

Reduce the header HTML’s own height first

Before changing command-line values, inspect the header file. Browser-style default margins and explicit padding can make a short header occupy more vertical space than it appears to need. The official CLI example sets the header body to style="border:0; margin: 0;"; use the same principle for the body and any header elements whose spacing should be controlled.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Amazon Basics Multipurpose Copy Printer Paper, 8.5 x 11 Inches, 20 lb, 92 Bright, White, 1 Ream (500 Sheets), Jam-Free
  • 1 ream (500 sheets) of 8.5 x 11 white copier and printer paper for home or office use
  • Multipurpose letter size copy paper works with laser/inkjet printers, copiers and fax machines
  • Smooth 20lb weight paper for consistent ink and toner distribution; dries quickly and resists paper jams
  • Bright white paper (92 GE; 104 Euro) offers great contrast for crisp printing and vivid color
  • Virgin copy paper providing professional quality results; acid-free to prevent yellowing

Check the elements that can add height

  • Body: set its margin explicitly rather than relying on a browser default.
  • Paragraphs: inspect top and bottom margins, especially if the header is made from one or more <p> elements.
  • Tables and containers: check cell padding, borders, margins, and any fixed height or padding on wrapping elements.
  • Images: account for their rendered dimensions and any surrounding spacing.

For example, a deliberately compact header can start with the following structure. Replace the text with your own content and add only the spacing you intend:

<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <style>
    html, body { margin: 0; padding: 0; }
    p { margin: 0; }
  </style>
</head>
<body style="border:0; margin:0;">
  <p>Document header</p>
</body>
</html>

This is a starting point, not a promise that every header will render to the same height. Images, fonts, line wrapping, and other content affect the space the header needs. Set CSS values explicitly, then judge the result in the generated PDF.

Set header spacing and top margin together

Once the header’s CSS is under control, set --header-spacing to the distance you actually want between the header and the document content. The CLI reference gives its units as millimetres and its default as zero. If you see an unwanted gap, start at zero rather than assuming a positive spacing value is required.

Then set --margin-top to reserve enough room for the rendered header. The top margin and the header gap serve different purposes: the margin reserves page space; header spacing controls the gap to the content. A zero spacing value does not mean that the page’s top margin should also be zero.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
HP Printer Paper | 8.5 x 11 Paper | Copy &Print 20 lb | 1 Ream Case - 500 Sheets| 92 Bright | FSC Certified | 200060
  • HP Papers is sourced from renewable forest resources and has achieved production with 0% deforestation in North America. Each ream is wrapped in a polyurethane coated paper wrapper to protect the cut sheets from moisture damage
  • Sheet size – 8.5 x 11; Thickness – 20 pounds; Brightness – 92 bright white
  • HP Copy&Print20 20 pounds printer paper is Forest Stewardship Council (FSC) certified and contributes toward satisfying credit MR1 under LEED (Leadership in Energy and Environmental Design)
  • All HP Papers provide premium performance on HP equipment, as well as on all other printer and copier equipment; 100% satisfaction guaranteed; ColorLok technology provides more vivid colors, bolder blacks and faster drying
  • Superior quality, reliability, and dependability for high-volume printing at home, at school and in the office; HP Copy&Print20 print and copy paper prevents yellowing over time to ensure a long-lasting appearance for added archival quality
wkhtmltopdf --margin-top 12mm --header-spacing 0 --header-html header.html input.html output.pdf

Here, 12mm is an example configuration only—not a universal recommended margin. Measure or inspect the rendered header and replace it with a value that fits your content and desired breathing room. If the header is taller or wraps onto multiple lines, it may need more space.

Change one layer at a time

  1. Make unintended CSS margins and padding explicit in header.html.
  2. Set --header-spacing 0 and generate a PDF.
  3. Adjust --margin-top to make room for the actual rendered header and the separation you want.
  4. If a visible gap is still needed between header and content, increase --header-spacing only as much as required.

Changing one setting at a time makes it easier to identify which layer caused the blank space. Keep the input document and header content fixed while comparing each output.

Why setting the top margin to zero can hide the header

Do not use --margin-top 0 as a general whitespace fix when the HTML header must remain visible. A report for wkhtmltopdf 0.12.5 with patched Qt describes the header becoming invisible when --header-html was combined with a zero top margin. That issue is evidence of a version- and build-specific failure mode, not proof that every build behaves identically.

If the header disappears after reducing the margin, restore a nonzero top margin large enough to accommodate it and test again. Reduce excess space through the header’s CSS and, if needed, the header-to-content spacing instead of assuming that the reserved page margin can safely be removed.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Amazon Basics Multipurpose Copy Printer Paper, 20 lb, 8.5 x 11 Inches, 3 Reams (1,500 Sheets), 92 Bright White for Home Use
  • 3 ream case (1,500 sheets) of 8.5 x 11 white copier and printer paper for home or office use
  • Multipurpose letter size copy paper works with laser/inkjet printers, copiers and fax machines
  • Smooth 20lb weight paper for consistent ink and toner distribution; dries quickly and resists paper jams
  • Bright white paper (92 GE; 104 Euro) offers great contrast for crisp printing and vivid color
  • Virgin copy paper providing professional quality results; acid-free to prevent yellowing

Check your wkhtmltopdf version and build

Header whitespace behavior can vary with the wkhtmltopdf version and build. Issue reports describe spacing that increased as header HTML content changed, with manual top- and bottom-margin adjustment used as a workaround; the report is marked fixed for milestone 0.12.7. That milestone note is useful when diagnosing the reported behavior, but it does not establish that every distribution ships the same build or that all header-layout problems are fixed by upgrading.

Record the version and build details shown by your installed wkhtmltopdf --version command when comparing output or reporting a problem. When a header’s spacing changes unexpectedly with its contents, compare the same input on the relevant installed builds if you can. Do not assume two installations are equivalent solely because they use the same command name.

Test headers whose content changes

A header that fits on one line on one page may wrap or become taller on another. Because an issue report describes whitespace changing with header HTML contents, test representative pages rather than judging the PDF from only its first page.

  • Include the shortest and longest header values you expect.
  • Check pages where text may wrap or where an image is present.
  • Inspect the first page and pages with different header content.
  • Keep the version, header file, input, margin, and spacing values noted so comparisons are meaningful.

If the header’s height changes with content, a margin that fits a short heading may not leave enough space for a longer one. Adjust the layout or reserved margin to accommodate the cases your documents actually produce.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Amazon Basics Multipurpose Copy Printer Paper, 20 lb, 8.5 x 11 Inches, 5 Reams (2,500 Sheets), 92 Bright White
  • 5 ream case (2,500 sheets) of 8.5 x 11 white copier and printer paper for home or office use
  • Multipurpose letter size copy paper works with laser/inkjet printers, copiers and fax machines
  • Smooth 20lb weight paper for consistent ink and toner distribution; dries quickly and resists paper jams
  • Bright white paper (92 GE; 104 Euro) offers great contrast for crisp printing and vivid color
  • Virgin copy paper providing professional quality results; acid-free to prevent yellowing

Common problems and fixes

Symptom Likely layer to inspect What to try
A blank band remains even though header spacing is zero. Header HTML margins, padding, or content height; also the page’s top margin. Set CSS margins and padding explicitly, then reduce --margin-top only while keeping enough room for the rendered header.
The header appears too far from the document content. --header-spacing. Start at 0 and increase only if a visible gap is desired.
The header is cut off or prints outside the page. The relationship between rendered header height, --margin-top, and spacing. Reserve adequate top margin for the header. The project documentation warns that an overly large header spacing can push the header outside the PDF and points to margin.top as the correction.
The header disappears after reducing the top margin to zero. Top margin and version/build behavior. Restore a nonzero --margin-top, then trim CSS spacing or header spacing separately. A 0.12.5 patched-Qt issue report documents this failure mode.
The blank space changes when the header text or contents change. Rendered header height and wkhtmltopdf version/build. Test short and long representative headers, compare the installed version/build, and adjust the margin for the tallest expected header if needed.

These are diagnostic paths, not guarantees that a particular setting is responsible in every PDF. Change one factor at a time and inspect the rendered result.

Performance, reliability, and configuration notes

The documented controls discussed here are layout settings. The available project references do not establish a general speed improvement from reducing header whitespace, so treat this as a formatting change rather than a performance optimization. Likewise, no prevalence or performance statistic is established for this issue.

For reliable comparisons, save the exact command, input HTML, header HTML, and version/build used for each test. Render representative pages after changing the header or its CSS. A PDF that looks correct for a short header does not by itself establish that longer or differently formatted headers will fit.

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 your actual goal is to capture a website as an image or PDF—not to tune an existing wkhtmltopdf document—you can use ScreenshotNeo, a website screenshot API and MCP server. It does not replace wkhtmltopdf’s header-margin controls; it is an alternative for website captures. Its API accepts a URL and can return a screenshot or PDF. See the ScreenshotNeo API documentation.

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.
Best Value
Amazon Basics Multipurpose Copy Printer Paper, 20 lb, 8.5 x 11 Inches, 8 Reams (4,000 Sheets), 92 Bright White, Great for Crisp Ink Printing
  • 8 ream case (4,000 sheets) of 8.5 x 11 white copier and printer paper for home or office use
  • Multipurpose letter size copy paper works with laser/inkjet printers, copiers and fax machines
  • Smooth 20lb weight paper for consistent ink and toner distribution; dries quickly and resists paper jams
  • Bright white paper (92 GE; 104 Euro) offers great contrast for crisp printing and vivid color
  • Virgin copy paper providing professional quality results; acid-free to prevent yellowing
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 the shot; each step can be turned off. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed, and the response identifies the page verdict and billing status in headers. An MCP server offers take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients. The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots.

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

Frequently Asked Questions

Does –header-spacing use inches or millimetres?

The wkhtmltopdf CLI reference specifies millimetres.

Is wkhtmltopdf 0.12.7 guaranteed to fix every header-spacing problem?

No. The issue report is marked fixed for milestone 0.12.7, but that does not establish that every packaged build contains the fix or that every whitespace problem has the same cause.

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.

Quick Recap

Bestseller No. 1
Amazon Basics Multipurpose Copy Printer Paper, 8.5 x 11 Inches, 20 lb, 92 Bright, White, 1 Ream (500 Sheets), Jam-Free
Amazon Basics Multipurpose Copy Printer Paper, 8.5 x 11 Inches, 20 lb, 92 Bright, White, 1 Ream (500 Sheets), Jam-Free
1 ream (500 sheets) of 8.5 x 11 white copier and printer paper for home or office use; Virgin copy paper providing professional quality results; acid-free to prevent yellowing
$6.97
Bestseller No. 2
HP Printer Paper | 8.5 x 11 Paper | Copy &Print 20 lb | 1 Ream Case - 500 Sheets| 92 Bright | FSC Certified | 200060
HP Printer Paper | 8.5 x 11 Paper | Copy &Print 20 lb | 1 Ream Case - 500 Sheets| 92 Bright | FSC Certified | 200060
Sheet size – 8.5 x 11; Thickness – 20 pounds; Brightness – 92 bright white
$6.97
Bestseller No. 3
Amazon Basics Multipurpose Copy Printer Paper, 20 lb, 8.5 x 11 Inches, 3 Reams (1,500 Sheets), 92 Bright White for Home Use
Amazon Basics Multipurpose Copy Printer Paper, 20 lb, 8.5 x 11 Inches, 3 Reams (1,500 Sheets), 92 Bright White for Home Use
Virgin copy paper providing professional quality results; acid-free to prevent yellowing
$21.96
Bestseller No. 4
Amazon Basics Multipurpose Copy Printer Paper, 20 lb, 8.5 x 11 Inches, 5 Reams (2,500 Sheets), 92 Bright White
Amazon Basics Multipurpose Copy Printer Paper, 20 lb, 8.5 x 11 Inches, 5 Reams (2,500 Sheets), 92 Bright White
Virgin copy paper providing professional quality results; acid-free to prevent yellowing
$29.14
Bestseller No. 5
Amazon Basics Multipurpose Copy Printer Paper, 20 lb, 8.5 x 11 Inches, 8 Reams (4,000 Sheets), 92 Bright White, Great for Crisp Ink Printing
Amazon Basics Multipurpose Copy Printer Paper, 20 lb, 8.5 x 11 Inches, 8 Reams (4,000 Sheets), 92 Bright White, Great for Crisp Ink Printing
Virgin copy paper providing professional quality results; acid-free to prevent yellowing
$53.19

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.