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

Control wkhtmltopdf pagination with CSS first: use page-break-before: always or page-break-after: always when a break is mandatory, and page-break-inside: avoid when a block should stay together. Then set the paper size, orientation and margins deliberately, because those options determine how much content is available before wkhtmltopdf creates an automatic break.

The key limitation is physical: avoid is a request not to split a block, not a way to compress a block that is taller than a page. The following patterns show exactly where to put each rule, how to invoke wkhtmltopdf, and how to diagnose breaks that still occur.

How wkhtmltopdf decides where pages end

wkhtmltopdf converts HTML page objects into a PDF. Its command shape is:

wkhtmltopdf [GLOBAL OPTION]... [OBJECT]... <output file>

A page object is one web page in the input. A command can contain several objects, and options can be global or attached to a particular object. Pagination is therefore the result of two layers:

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.
#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
  • CSS rules request a break or ask the renderer to avoid splitting a block.
  • PDF geometry defines the available page area. Paper size, explicit width and height, orientation, and all four margins change how much content fits before the next automatic break.

If you change geometry, the same HTML can paginate differently even when its CSS has not changed.

The three CSS controls

Property Useful values What it does Strength
page-break-before auto, always, avoid, left, right, inherit Controls whether a break is placed before a block-level element. always requests a mandatory break before the element.
page-break-after auto, always, avoid, left, right, inherit Controls whether a break is placed after a block-level element. always requests a mandatory break after the element.
page-break-inside auto, avoid, inherit Asks the renderer not to split a block-level element internally. avoid is discretionary when the block can fit.

These properties are defined for block-level boxes in visual paged media. Apply them to elements such as headings, sections, paragraphs, tables or dedicated block containers rather than relying on an inline element.

Force a section onto a new page

Put the break on the element that must begin the new page:

<h2 class="new-page">Appendix</h2>
.new-page {
  page-break-before: always;
}

The heading remains in the document flow, but wkhtmltopdf starts it after a forced page boundary. This is appropriate for appendices, chapter starts and other sections whose first line must not share the previous page.

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

Break after a complete block

Use page-break-after when the current block must finish a page before the next content starts:

.appendix {
  page-break-after: always;
}

This is useful when a self-contained cover, appendix or notice should be followed by a fresh page regardless of how much room remains.

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⁴

Use a dedicated break element

A dedicated block keeps the pagination marker easy to maintain in generated HTML:

<div class="page-break"></div>
.page-break {
  page-break-before: always;
}

Because the marker is a block-level element, the property applies to the box wkhtmltopdf paginates.

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

Keep notices, cards and rows together when possible

Apply page-break-inside: avoid to the block that should remain intact:

.keep-together {
  page-break-inside: avoid;
}
<section class="keep-together">
  <h3>Payment notice</h3>
  <p>The notice and its explanation should stay together when there is enough room.</p>
</section>

The rule is a preference to avoid an internal split. It cannot make an oversized block physically smaller. If the block is taller than the usable page area, wkhtmltopdf still has to paginate its contents.

Tables and individual rows

To keep a table from splitting internally, put the rule on the table or on the block that wraps the table:

.invoice-table {
  page-break-inside: avoid;
}

Whether an individual row remains with its neighbors depends on the boxes produced by the HTML and the space available. Test the actual generated structure, and avoid assuming that a very large table can fit on one page merely because it has an avoid rule.

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.
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.

A complete minimal example

Save this as report.html:

<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <style>
    body { font-family: sans-serif; }
    h2.new-page { page-break-before: always; }
    .cover { page-break-after: always; }
    .notice { page-break-inside: avoid; }
    .page-break { page-break-before: always; }
  </style>
</head>
<body>
  <section class="cover">
    <h1>Quarterly report</h1>
    <p>This cover always occupies the first page.</p>
  </section>

  <h2>Summary</h2>
  <p>Summary content flows normally and can be split by automatic pagination.</p>

  <h2 class="new-page">Appendix</h2>
  <section class="notice">
    <h3>Important notice</h3>
    <p>This block is kept together when it fits in the remaining page area.</p>
  </section>
</body>
</html>

Convert it with:

wkhtmltopdf report.html report.pdf

The cover ends with a forced break, the appendix heading starts on a new page, and the notice is protected from an avoidable internal split.

Set page geometry before tuning CSS

wkhtmltopdf exposes global and page-level geometry options. The relevant controls are:

Option Purpose Pagination effect
--page-size Selects a named paper size. Changes the page width and height available to content.
--page-width Sets an explicit page width. Changes line wrapping and horizontal room, which can change vertical length.
--page-height Sets an explicit page height. Changes how many lines or blocks fit before an automatic break.
--orientation Chooses page orientation. Switching orientation changes both usable dimensions and wrapping.
--margin-top, --margin-right, --margin-bottom, --margin-left Set each page margin. Larger margins reduce the content area and can move breaks earlier.

For a controlled build, choose these values first, then adjust break rules. Otherwise you may fix a break for one geometry and immediately invalidate it by changing the paper size or margins.

Example with explicit geometry

wkhtmltopdf 
  --page-size A4 
  --orientation Portrait 
  --margin-top 18mm 
  --margin-right 15mm 
  --margin-bottom 18mm 
  --margin-left 15mm 
  report.html report-a4.pdf

If you use explicit dimensions instead of a named size, replace --page-size with --page-width and --page-height as appropriate.

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

Make print CSS reach the conversion

A correct selector has no effect if its stylesheet is missing from the HTML, does not match the intended element, or is not active for the media mode used during conversion. When your layout relies on print-only rules, use wkhtmltopdf’s print-media-type page option so the print stylesheet is selected.

wkhtmltopdf --print-media-type report.html report-print.pdf

Keep the pagination declarations in the stylesheet that the conversion actually loads. For generated documents, inspect the final HTML rather than only the template: a missing class or malformed block can make a working rule appear to be ignored.

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
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Choosing between forced breaks and keep-together rules

Decision Use Result when there is room Result when content is too large
A section must start after a boundary page-break-before: always Break is requested before that block. The block still flows across pages if it cannot fit on one page.
A section must end before the next one page-break-after: always Break is requested after that block. The block itself is still paginated normally.
A notice or card should not be split page-break-inside: avoid Renderer tries to keep the block together. An oversized block is split because it cannot fit physically.

Use forced rules sparingly: each forced boundary consumes a page transition. Use avoid for local integrity, then verify the result at the final paper size and margins.

Troubleshoot unexpected automatic breaks

The rule appears to do nothing

  • Check that the selector matches the element in the converted HTML.
  • Confirm the stylesheet is included and loaded by the page object.
  • Verify that the target is a block-level element, because the properties are defined for block-level boxes.
  • Check whether another declaration overrides the rule in the active stylesheet.

A supposedly protected block still splits

Measure the block against the usable page area after margins are applied. page-break-inside: avoid cannot fit content that is taller than the page. Reduce the block’s content or change the page geometry if keeping it intact is essential.

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

The break moves after a margin or orientation change

This is expected: geometry changes the available content area and text wrapping. Treat page size, orientation and margins as part of the pagination specification, not as cosmetic settings.

Print-only rules are ignored

Ensure the conversion uses the print media mode. Add --print-media-type, then verify that the stylesheet containing the page-break declarations is available to the page object.

A break occurs before the wrong heading

Inspect the actual block carrying the class. Put page-break-before: always on the heading that must begin the page, or put page-break-after: always on the preceding block when the boundary belongs after that content.

A repeatable pagination workflow

  1. Build a small HTML fixture containing one forced-before case, one forced-after case and one keep-together case.
  2. Choose the final page size, orientation and four margins.
  3. Run wkhtmltopdf with those geometry options and the same media mode used in production.
  4. Inspect the output for selector mismatches, missing styles and blocks taller than one page.
  5. Only then add additional break rules to the full document.

This order separates CSS mistakes from geometry changes and makes a later layout adjustment easier to reason about.

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

Or skip the browser setup

If your goal is a clean image or PDF of a web page rather than controlling wkhtmltopdf’s HTML pagination, ScreenshotNeo provides a single-call screenshot API. It accepts cookie and consent banners like a visitor, then removes more than 60 known consent platforms, newsletter popups and chat widgets before capture; 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. An MCP server exposes take_screenshot, get_page_info and capture_pdf to Claude, Cursor and other MCP clients.

cURL

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

Python

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

Node.js

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://example.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

See the ScreenshotNeo documentation for the complete request options. The service supports full-page captures with lazy images loaded, CSS-selector element captures, dark mode, device presets or custom viewports, retina scale, PDF paper settings and page ranges, custom CSS and JavaScript, clicks before capture, selector hiding, selector/delay/network-idle waits, request and resource blocking, custom headers, cookies, user agents and authorization, timezone and geolocation, transparent backgrounds, resizing, chosen cache TTLs, signed links, asynchronous jobs with signed webhooks, bulk capture of up to 100 URLs per call, a usage API and an OpenAPI specification. Parameter names used by other screenshot APIs also work, easing migration.

Plan Included screenshots per month Price
Free 1,000 No card required
Starter 3,000 $5
Growth 15,000 $15
Pro 60,000 $39
Scale 250,000 $99
Business 1,000,000 $249

Yearly billing provides two months free, and every feature is included on every plan. Create a free ScreenshotNeo account to get 1,000 screenshots each month without a card.

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.