Set paper geometry explicitly in wkhtmltopdf, then make the HTML fit the resulting printable area. Use --page-size for A4, Letter, Legal and other presets; use --page-width and --page-height for custom sheets. Set --orientation and all four margins instead of relying on defaults. The wkhtmltopdf project manual for 0.12.6 with patched Qt documents A4 and Portrait as defaults, but explicit values make builds reproducible.
1. Decide whether you need a named paper size or custom dimensions
Start with the physical sheet your PDF must represent. A named preset is easiest when the destination is a standard format. Custom dimensions are appropriate for labels, forms, tickets or a nonstandard print stock.
Named paper sizes
The wkhtmltopdf usage manual documents A4, A3, Letter and Legal, among others. Its documented default is A4. Do not depend on that default when the size matters: write the choice into your command so another machine or wrapper cannot silently produce a different result. See the wkhtmltopdf usage documentation.
Custom width and height
Use --page-width and --page-height with units such as mm, cm, in or pt. For an A4-sized custom sheet, for example, use 210mm by 297mm. A custom pair describes the sheet itself; it does not automatically rotate when you change orientation, so keep the dimensions consistent with the intended layout.
#1 Best Overall
- 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
| Requirement | wkhtmltopdf setting | Use when |
|---|---|---|
| Standard sheet | --page-size A4, Letter, Legal, etc. |
The target is a recognized paper preset. |
| Exact sheet geometry | --page-width 210mm --page-height 297mm |
The stock is custom or a wrapper does not expose named presets. |
| Horizontal layout | --orientation Landscape |
Tables, charts or forms need more horizontal space. |
| Vertical layout | --orientation Portrait |
The normal document flow is taller than it is wide. |
2. Set orientation and margins independently
Orientation changes the page direction; it does not solve an oversized layout by itself. The CLI manual and the libwkhtmltox settings reference expose separate top, right, bottom and left margins. The documented CLI default is Portrait.
Margins reduce the usable content rectangle. If the sheet is 210mm wide and the left and right margins are 12mm, the content width is 186mm before accounting for borders, padding, scrollbars or positioned elements. A page can therefore have the correct paper size while its content is clipped or appears off-center.
3. A reproducible wkhtmltopdf command
This command creates an A4 portrait PDF with equal 12mm margins:
wkhtmltopdf
--page-size A4
--orientation Portrait
--margin-top 12mm
--margin-right 12mm
--margin-bottom 12mm
--margin-left 12mm
input.html output.pdf
For a custom A4-sized sheet, replace the page-size line:
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallwkhtmltopdf
--page-width 210mm
--page-height 297mm
--orientation Portrait
--margin-top 12mm
--margin-right 12mm
--margin-bottom 12mm
--margin-left 12mm
input.html output.pdf
Use the same units for comparable values and quote paths containing spaces. Put global options before the input and output arguments. If you are invoking wkhtmltopdf from a program, log the complete argument list and the binary version so a generated PDF can be reproduced.
Rank #2
- 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
4. Make the HTML fit the printable area
Control the root width
A fixed desktop canvas, wide table or absolutely positioned block can exceed the content rectangle even when the PDF page is correct. Prefer fluid widths such as width:100% and max-width:100%. For tables, use table-layout:fixed where appropriate, allow long words to wrap, and inspect cells with unbreakable URLs or code.
Account for box sizing
CSS width normally applies to the content box. Borders and padding can make the rendered box wider than the page. A print stylesheet commonly starts with:
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
img, svg, table { max-width: 100%; }
img { height: auto; }
Then add document-specific spacing inside the wkhtmltopdf margins rather than using a wrapper wider than the available area.
Recommended Free Tools
Check positioned and transformed elements
Fixed-width headers, negative margins, CSS transforms and absolute coordinates can shift content outside the page. Temporarily remove those rules to determine whether the defect is geometry or layout. Headers and footers also need their own spacing so they do not overlap the body.
5. CSS @page versus wkhtmltopdf options
CSS can express paper size, orientation and margins:
Rank #3
- 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
@page {
size: A4 portrait;
margin: 12mm;
}
The MDN @page reference notes that support varies by feature and browser or device generation. wkhtmltopdf is based on a particular Qt/WebKit build, and the reviewed documentation does not establish one precedence rule that applies to every build when CSS and CLI geometry conflict. For predictable output, set geometry on the wkhtmltopdf command line, keep @page as a design aid only when verified, and test the exact binary and Qt build deployed.
6. Verify the PDF, not just the command
- Open the PDF properties or inspect it with your PDF tooling to confirm the media-box dimensions match the required sheet.
- Print or render a page at 100% scale and check all four edges, especially the bottom margin and wide tables.
- Compare portrait and landscape outputs if the document contains horizontal content.
- Test pages with the longest text, largest images and deepest tables; a short sample can hide overflow.
- Record the wkhtmltopdf version, options, input URL or file and any CSS used.
Do not diagnose every alignment problem as a paper-size problem. A correctly sized sheet with a clipped fixed-width element is a content-layout failure; a centered document with unexpectedly large whitespace may be a margin or wrapper-width issue.
7. Troubleshooting common alignment failures
Everything is shifted to one side
Check left and right margins first, then inspect a fixed-width wrapper, body margin, asymmetric padding or an absolutely positioned child. Set body margins explicitly and temporarily outline major elements with outline:1px solid red.
The right edge or bottom is clipped
Measure the element’s outer width, including padding and borders, against the page width minus both horizontal margins. Reduce fixed widths, enable wrapping, and check for a table or image with an intrinsic width larger than its container.
The PDF is the wrong physical size
Look for a wrapper that omitted --page-size or supplied conflicting custom dimensions. Set one geometry explicitly, verify units, and confirm that a higher-level library did not override the command.
Rank #4
- 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
@page appears to do nothing
This can be a compatibility limitation of the installed WebKit/Qt build. Move the essential size, orientation and margins to CLI options, then retest with the exact production binary.
Landscape still looks cramped
Changing orientation gives the sheet a different direction but does not remove margins or make a fixed-width design responsive. Recalculate the available width and inspect media queries, transforms and hard-coded columns.
Different machines produce different results
Pin or record the wkhtmltopdf release and patched-Qt build, use explicit geometry, and avoid relying on undocumented defaults. Font availability, image loading and external CSS can also alter line wrapping and pagination.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.8. Performance and reliability considerations
Page geometry itself is inexpensive; unstable input content is usually the larger source of inconsistent PDFs. Ensure stylesheets, fonts and images are available before conversion, avoid layout rules that depend on a modern browser feature unsupported by the deployed WebKit, and use representative long pages in automated tests. Keep a known-good command for each paper format rather than changing several variables at once.
For forms and reports, treat the sheet dimensions and printable content rectangle as separate requirements. Document both in your specification: for example, “A4 portrait, 12mm margins, body width no greater than the resulting content area.” That makes review and regression testing concrete.
Free tools Windows power users keep installed
One-click scans. No signup required.
Best Value
- 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
Or skip the browser setup
When your goal is a clean image or PDF of a URL rather than a local wkhtmltopdf conversion, ScreenshotNeo provides a website screenshot API and MCP server. It accepts a URL and can return PNG, JPEG, WebP or PDF. Cookie and consent banners, newsletter popups and chat widgets are removed before capture; bot checks, blank pages, timeouts, failed loads and cache hits are not billed, and response headers identify the page verdict and billing status. Its MCP tools—take_screenshot, get_page_info and capture_pdf—work with Claude, Cursor and other MCP clients.
One-call cURL example (see the ScreenshotNeo documentation):
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(`${res.status} ${res.statusText}`);
const fs = await import('node:fs/promises');
await fs.writeFile('shot.webp', Buffer.from(await res.arrayBuffer()));
Every feature is included on every plan. The Free plan provides 1,000 screenshots per month without a card; paid plans start at $5 for 3,000 shots. Create a free ScreenshotNeo account to try it.
Frequently Asked Questions
What units can wkhtmltopdf use for custom dimensions?
The command accepts dimensions with units such as mm, cm, inches and points; include the unit explicitly in each width, height and margin value.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →Should I use A4 or Letter?
Use the sheet required by your printer, customer or archive. A4 and Letter are different physical sizes, so choose deliberately rather than inheriting the A4 default.
Can CSS alone control wkhtmltopdf page geometry?
CSS @page can express the intent, but support varies by build. Put required geometry in CLI options and validate CSS behavior on the exact binary 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.




