October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
CSS

How to Prevent Extra White Space at wkhtmltopdf Page Breaks

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

Extra white space in a wkhtmltopdf PDF usually comes from one of five places: a block the renderer keeps together, a table row or header that cannot split, header/footer spacing, page margins, or smart shrinking. Find which element sits at the break, change one factor at a time, and compare PDFs using the same wkhtmltopdf build. The CSS rule page-break-inside: avoid can keep a suitable block intact, but it can also move that block to the next page and leave a larger gap behind.

Start by locating the source of the gap

Do not begin by adding arbitrary negative margins or inserting blank paragraphs. Open the generated PDF and identify the first element after the whitespace: a heading, paragraph, image, table row, or the page header. Then inspect the HTML and print CSS for that element and its ancestors.

  • Record the wkhtmltopdf version and build used for every test.
  • Keep the input HTML, fonts, assets, command-line options, and page size unchanged while testing one variable.
  • Check whether the gap appears only before a table, only after a heading, or at every page boundary.

Different builds and documents paginate differently. Issue reports demonstrate particular behaviors, not a universal fix for every wkhtmltopdf deployment.

Use break-avoidance rules selectively

What page-break-inside: avoid actually does

page-break-inside: avoid requests that the renderer not place a page break inside an element. It is the legacy name for the modern break-inside property. The rule is useful for a short card, a heading with its first paragraph, or a table row that should remain intact.

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

If the element is taller than the remaining space, wkhtmltopdf may move the whole element to the next page. The unused area on the previous page is therefore an expected trade-off, not proof that the rule failed. Avoid applying it to large containers, long articles, or an entire table.

A controlled baseline stylesheet

.keep-together {
  page-break-inside: avoid;
}

.table-wrap {
  page-break-inside: auto;
}

table {
  page-break-inside: auto;
  border-collapse: collapse;
}

tr {
  page-break-inside: avoid;
  page-break-after: auto;
}

thead {
  display: table-header-group;
}

tfoot {
  display: table-footer-group;
}

Apply .keep-together only to content that is small enough to fit on one page. Leave the table itself breakable, avoid large row content, and use row-level avoidance where it helps. Test the resulting PDF because older wkhtmltopdf builds do not honor every CSS rule identically.

Fix table-related whitespace

Keep rows intact, not the entire table

A common symptom is a large gap before a table or a table that jumps to the next page. Start with tr { page-break-inside: avoid; }, then inspect the row that follows the gap. A row containing a long paragraph, large image, or nested table may be too tall to fit, so the renderer moves it.

Repeat headers without creating orphaned headers

Use display: table-header-group on thead and display: table-footer-group on tfoot so continuation pages identify the columns. Some wkhtmltopdf issue reports describe awkward output in which a repeated header appears without a corresponding data row. Test short, medium, and long tables, and check the first and last page separately.

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

Check markup that silently enlarges a row

  • Remove empty <tr>, <td>, and paragraph elements.
  • Set image dimensions or constrain images with max-width: 100%.
  • Look for excessive cell padding, line-height, or a fixed height.
  • Ensure a nested block is not carrying page-break-inside: avoid from a broad selector.
  • Confirm that a very long unbroken URL or code sample can wrap.

Inspect margins, headers, and footers

Page geometry can create a gap that looks like a content problem. wkhtmltopdf reserves space for margins and for header or footer content independently of the document body.

Set the page margins explicitly

wkhtmltopdf 
  --page-size A4 
  --margin-top 18mm 
  --margin-right 12mm 
  --margin-bottom 18mm 
  --margin-left 12mm 
  input.html output.pdf

Use the units supported by your build and keep the values consistent across comparisons. If the gap is exactly the same on every page, compare these settings first.

Check header and footer spacing

When a header or footer is enabled, options such as --header-spacing and --footer-spacing add separation between that material and the body. A header that is taller than expected can push the first body element down; a footer can reduce the usable area at the bottom and force an otherwise suitable block onto the next page.

wkhtmltopdf 
  --header-html header.html 
  --header-spacing 4 
  --footer-html footer.html 
  --footer-spacing 4 
  input.html output.pdf

As a diagnostic, render once with both header and footer disabled. If the whitespace disappears, re-enable them one at a time and reduce the spacing or the HTML height. A reported 0.12.6 header-spacing problem when only a footer was specified is version-specific; treat it as a reason to test your build, not as proof that every installation has the defect.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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.

Compare smart shrinking

wkhtmltopdf enables smart shrinking by default in its documented command-line usage. Shrinking changes the effective scale so content can fit the page width, which can alter line wrapping and therefore page-break positions. It may make a gap appear or disappear without changing your CSS.

Render both modes

# Default smart shrinking
wkhtmltopdf input.html smart.pdf

# Comparison render
wkhtmltopdf --disable-smart-shrinking input.html no-shrink.pdf

Compare font size, line wraps, table widths, and the exact break where the gap occurs. Disabling shrinking is not a guaranteed whitespace fix; it is a controlled experiment. If the unshrunk version is correct, adjust CSS widths, font sizes, or page margins deliberately rather than relying on an accidental scale.

A repeatable troubleshooting procedure

  1. Reduce the case. Copy the problem page into a minimal HTML file with the same CSS, table, images, and fonts.
  2. Identify the boundary. Temporarily add an outline such as * { outline: 0.2mm solid rgba(255,0,0,.2); } to see which box owns the empty area.
  3. Test content rules. Remove broad page-break-inside: avoid declarations, then add avoidance only to the affected row or small block.
  4. Test table structure. Toggle row avoidance and repeating header/footer groups independently; try short and long tables.
  5. Test geometry. Disable headers and footers, set explicit margins, and render again.
  6. Test scaling. Compare default smart shrinking with --disable-smart-shrinking.
  7. Restore features one at a time. The first change that recreates the gap identifies the area to fix.

Common symptoms and targeted fixes

Symptom Likely cause What to try
Large blank area before one paragraph or card The block is kept together and does not fit Remove avoidance from the parent; apply it only to a smaller block, or accept the move to the next page.
Gap before a table A row, nested table, or table-wide avoidance rule Keep the table breakable; use row-level avoidance and inspect the next row’s height.
Header repeats with no data row Table pagination edge case Test thead repetition with several table lengths and revise the markup or break position.
Every page has the same top or bottom gap Margins, header spacing, or footer spacing Render without header/footer and set all margins explicitly.
Whitespace changes when text wraps Smart shrinking or width constraints Compare with --disable-smart-shrinking; then correct widths and line wrapping.
Only one machine shows the problem Different wkhtmltopdf build, fonts, or libraries Record versions, install the same build, and verify that fonts and assets resolve identically.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Performance and reliability considerations

Rendering time is usually dominated by loading remote CSS, fonts, images, JavaScript, and the number of pages. A minimal reproduction is faster and makes pagination changes easier to attribute. For production jobs:

  • Pin the wkhtmltopdf version and record the command line with the generated PDF.
  • Make assets deterministic; missing fonts or late-loading images change element heights.
  • Prefer explicit image dimensions and avoid JavaScript that changes layout after printing starts.
  • Keep a visual regression sample containing a short table, a multi-page table, headers, footers, and a near-page-length block.
  • Change one CSS or command-line setting per test and keep the PDFs for comparison.

There is no published rate that predicts how often a particular whitespace fix works. Treat each issue report as a case-specific example and validate the output produced by your own build.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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

Or skip the browser setup

If your real goal is a clean image or PDF of a web page rather than maintaining a wkhtmltopdf pipeline, ScreenshotNeo provides a single HTTP request. Before capture it accepts cookie or consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each cleanup step can be disabled. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and the response identifies the result with X-Page-Verdict and X-Billed headers.

Read the full parameter list in the ScreenshotNeo documentation. The API supports full-page captures with lazy images loaded, CSS-selector element captures, dark mode, device presets and custom viewports, retina scale, PDF paper size and margins, custom CSS and JavaScript, click actions, selector or network-idle waits, request and resource blocking, headers, cookies, user agents, authorization, timezone, geolocation, transparent backgrounds, resizing, selectable cache TTLs, signed image links, asynchronous jobs with signed webhooks, bulk capture of up to 100 URLs per call, a usage API, and an OpenAPI specification.

cURL

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

Python

import requests

r = requests.get(
    "https://api.screenshotneo.com/v1/shot",
    params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"},
    timeout=90,
)
r.raise_for_status()
open("shot.webp", "wb").write(r.content)

Node.js

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const data = Buffer.from(await res.arrayBuffer());
require('fs').writeFileSync('shot.webp', data);

ScreenshotNeo has a free plan with 1,000 screenshots per month and no card required. Paid plans start at $5 for 3,000 shots; every feature is included on every plan, and yearly billing provides two months free. An MCP server also lets Claude, Cursor, or another MCP client call take_screenshot, get_page_info, and capture_pdf. Create a free ScreenshotNeo account to try it without entering a card.

Frequently Asked Questions

Does adding page-break-inside: avoid always remove the blank space?

No. It only requests that the element stay intact. If it cannot fit in the remaining area, wkhtmltopdf may move it to the next page and leave more space behind.

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

Should I disable smart shrinking in production?

Not automatically. Render with and without --disable-smart-shrinking, compare wrapping and breaks, and choose the mode that matches your required layout for the pinned build.

Why does a table header appear at the bottom of a page by itself?

Repeating table groups can produce awkward edge cases in some builds. Test the actual table lengths, inspect the break position, and adjust markup or pagination rules rather than assuming the header CSS is universally reliable.

Which wkhtmltopdf version fixes page-break whitespace?

No single version-wide fix is established. Behavior depends on the build, document, CSS, fonts, and command-line geometry, so record and test the version you deploy.

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.

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

Leave a Reply

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

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.

Read next

Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair 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.