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

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

To control the width of a PDF made with wkhtmltopdf, work from the outside in: choose the paper width, subtract the left and right margins, set the browser viewport, then make the page’s CSS content fit that usable space. If a page looks unexpectedly narrow, check those values and the active screen or print styles before changing zoom.

How wkhtmltopdf decides how wide content appears

A PDF’s content width is not a single setting. It is the result of several interacting dimensions:

  1. Paper width: the full width of the PDF page, set by --page-size or custom page dimensions.
  2. Margins: the left and right space reserved around the content.
  3. Usable PDF width: paper width minus both horizontal margins.
  4. Browser viewport: the emulated window width used while rendering the HTML.
  5. CSS content width: the width of the page wrapper, tables, images and other layout elements.

For example, a wrapper fixed at 1,300 pixels cannot fit naturally into a narrower viewport or printable area. Depending on the page and renderer behavior, the result can look clipped, overflow, or be scaled down. Conversely, a narrow CSS max-width can leave large unused bands even when the PDF page itself is wide.

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

Set the page geometry deliberately first. Then make the viewport and CSS agree with the intended content width. Treat zoom as a final scale adjustment, not a substitute for correcting a mismatch in dimensions.

Set paper size and usable width

The wkhtmltopdf project documentation says the default rendered page size is A4 and that --page-size can select other sizes such as A3, Letter and Legal. Use that option when a standard paper size is appropriate; use custom page dimensions when the output needs a specific width or height.

Choose a standard page size

For A4, set --page-size A4. For another supported paper size, replace A4 with the required value. A paper-size choice sets the outer page, not the width your HTML can occupy: margins still reduce the printable area.

Use a custom page width

The command-line interface also provides --page-width and --page-height for fine-grained dimensions. Use them when a standard paper size does not match the intended output. Keep the dimension units consistent with the units used for margins so that the geometry is easy to audit.

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

Calculate the available width

Use this relationship when planning the layout:

usable width = page width − left margin − right margin

Rank #2

Set --margin-left and --margin-right explicitly rather than relying on defaults. Their values determine how much of the page remains for the rendered document. The CSS wrapper should fit that available area at the chosen viewport; it should not assume the entire physical page is content space.

Align the viewport and CSS layout

--viewport-size sets the emulated browser window size. This is especially relevant when responsive breakpoints or viewport-relative CSS units such as vw affect the page. A viewport that is narrower or wider than the design target can cause the browser to select different responsive rules or compute different dimensions.

Choose the viewport to match the design

Pick a deliberate viewport width based on the layout you want rendered, then check that the main wrapper can fit it. A viewport value is not a guarantee that the same number of pixels will become the PDF’s printable width: the paper and margins define the PDF geometry, while the viewport influences browser layout.

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.

Inspect fixed widths and maximum widths

Review the page’s main container and any broad elements for declarations such as width: 1200px or max-width: 900px. A fixed width larger than the intended content area is a common source of overflow or apparent shrinking. A restrictive maximum width may instead make content look squeezed despite ample page space. Adjust the CSS to fit the chosen viewport and usable PDF width rather than blindly increasing the paper size.

Also inspect wide tables, images, and long unbreakable strings. These can exceed the wrapper even when the wrapper itself is correctly sized. Decide whether to wrap, resize, constrain, or intentionally allow overflow for each element.

Choose screen CSS or print CSS

wkhtmltopdf renders screen media by default. If the stylesheet intended for PDF output is inside @media print, add --print-media-type so the renderer uses print media. If the screen stylesheet is the intended source of truth, do not switch media types without checking how its responsive rules affect the viewport and width.

Before changing dimensions, confirm which stylesheet is active. Print CSS can change container widths, hide elements, or alter table behavior; a PDF using screen CSS may therefore differ from a browser’s print output. Make one controlled run with the desired media mode and inspect the resulting page.

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

A practical wkhtmltopdf command

This command is a starting pattern, not a universal preset. Adjust the viewport and margins to match the design and target paper:

wkhtmltopdf 
  --page-size A4 
  --margin-left 12mm --margin-right 12mm 
  --viewport-size 1200x900 
  --print-media-type 
  --disable-smart-shrinking 
  input.html output.pdf

Here, A4 establishes the paper size, explicit horizontal margins establish the available width, and the viewport gives responsive layouts a defined browser window. Print media is enabled for pages whose print stylesheet should control rendering. Smart shrinking is disabled to make it easier to compare the declared geometry with the result. If your document is designed for screen styles, omit --print-media-type; if shrinking is appropriate for your page, compare with smart shrinking enabled before deciding to disable it.

For a fair comparison between runs, record the page size or custom dimensions, left and right margins, viewport, media mode, smart-shrinking setting, and zoom. Change one factor at a time; otherwise it is difficult to tell which adjustment affected the layout.

When to change smart shrinking or zoom

wkhtmltopdf’s CLI documents --disable-smart-shrinking as disabling WebKit’s intelligent shrinking. If the output appears scaled down, compare a run with that option and a run without it while keeping the other geometry fixed. This helps distinguish a shrinking effect from a CSS width or viewport mismatch.

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

--zoom changes apparent scale. Adjust it only after paper width, margins, viewport, CSS widths, media mode and smart-shrink behavior are stable. Otherwise, zoom may make one element appear closer to the desired size while masking an underlying mismatch across the page.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Library settings for applications

When using libwkhtmltox rather than the command-line interface, the corresponding concepts are available as settings. The documented settings include:

  • size.width and size.pageSize for page sizing.
  • Margin settings, including the horizontal margins.
  • screenWidth for the emulated screen width.
  • smartWidth for smart-width behavior.
  • load.zoomFactor for scale.
  • load.printMediaType for print-media rendering.

Use the setting names appropriate to the library interface and version you have installed; do not assume a command-line flag name is also the exact library property name. Keep the same width chain in your application configuration: page dimensions, margins, screen width, CSS container, and only then scale.

Troubleshoot a squeezed or scaled PDF

  1. Confirm the installed binary. Check which wkhtmltopdf build is actually running and whether it is the patched-Qt build required by the feature set you intend to use. A different build may not support the same capabilities.
  2. Fix page size and horizontal margins. Set a known page size or custom dimensions and explicit left and right margins. Calculate the usable width before changing CSS.
  3. Set a deliberate viewport. Add or adjust --viewport-size if responsive breakpoints or vw units influence the layout. Record the selected width.
  4. Inspect media rules and containers. Check whether screen or print media is active, then examine @media print, fixed widths and max-width rules on the main wrapper.
  5. Compare smart shrinking. Run otherwise identical captures with smart shrinking enabled and disabled. Note whether the scale changes.
  6. Adjust zoom last. Once the geometry and stylesheet behavior are settled, make a small, deliberate scale adjustment if needed.
  7. Check overflowing elements. Inspect wide tables, images and long strings that cannot break. Fix their individual sizing or wrapping behavior instead of shrinking the entire page to accommodate one oversized element.

Or skip the browser setup

If you need a website screenshot or PDF capture rather than control over wkhtmltopdf’s CSS layout, ScreenshotNeo is a separate API option. It does not expose wkhtmltopdf’s page-width geometry settings; use the method above when precise HTML-to-PDF layout control is the requirement.

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.

One GET request can return a screenshot or PDF. For example, this cURL request saves a WebP capture of Stripe; see the ScreenshotNeo API documentation for parameters and response details:

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 supported cookie-consent banners, newsletter popups and chat widgets before capture; bot checks, blank pages and failed loads are not billed. It also provides an MCP server with tools for AI agents, and includes 1,000 screenshots per month on its free plan with no card required; paid plans start at $5 for 3,000. Sign up for free to try it.

Frequently Asked Questions

Does –viewport-size set the PDF page width?

No. It sets the emulated browser window size; page dimensions and margins determine the PDF’s physical content area.

Can wkhtmltopdf use a custom page size?

Yes. The CLI documents –page-width and –page-height in addition to standard sizes selected with –page-size.

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

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.