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.

Set the margins with wkhtmltopdf’s page options before the input file and output filename: wkhtmltopdf --margin-top 20mm --margin-bottom 25mm input.html output.pdf. The short forms are -T and -B. Values must include a unit, such as mm or cm. For the library API, set the global PDF settings margin.top and margin.bottom. Then open the generated PDF and check that the body, header and footer occupy the intended printable area.

Use the CLI margin options

The normal command-line interface exposes separate controls for the top and bottom page margins. Put these global options before the input object and output filename:

wkhtmltopdf --margin-top 20mm --margin-bottom 25mm input.html output.pdf

--margin-top (also -T) sets the top margin. --margin-bottom (also -B) sets the bottom margin. The options affect the page area around the rendered document; they do not change the HTML source itself.

Purpose Long option Short option Example value
Top page margin --margin-top -T 20mm
Bottom page margin --margin-bottom -B 25mm

The option names and short forms are documented in the official wkhtmltopdf usage documentation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
PDF Extra 2024| Complete PDF Reader and Editor | Create, Edit, Convert, Combine, Comment, Fill & Sign PDFs | Lifetime License | 1 Windows PC | 1 User [PC Online code]
  • EDIT text, images & designs in PDF documents. ORGANIZE PDFs. Convert PDFs to Word, Excel & ePub.
  • READ and Comment PDFs – Intuitive reading modes & document commenting and mark up.
  • CREATE, COMBINE, SCAN and COMPRESS PDFs
  • FILL forms & Digitally Sign PDFs. PROTECT and Encrypt PDFs
  • LIFETIME License for 1 Windows PC or Laptop. 5GB MobiDrive Cloud Storage Included.

Choose units and values deliberately

Pass a unit-bearing numeric value rather than a bare number. The API reference uses 2cm as an example, and the same style makes command-line settings unambiguous.

  • 15mm is a compact metric margin.
  • 2cm is equivalent to 20mm and is easier to read when designing a generous print border.
  • Use the same unit for both edges when you want a symmetrical layout, or set each edge independently when a header or footer needs different space.

There is no universal margin value in the documentation. Choose a value from the printable area your document needs and from the space consumed by any header or footer, then verify the actual PDF.

Common command patterns

Set both margins with long options

wkhtmltopdf --margin-top 20mm --margin-bottom 25mm input.html output.pdf

This is the clearest form for scripts and team documentation because the purpose of each value is visible.

Use the short options

wkhtmltopdf -T 20mm -B 25mm input.html output.pdf

The short flags produce the same settings. Keep the values immediately after their corresponding options.

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

Give the top and bottom different priorities

wkhtmltopdf --margin-top 35mm --margin-bottom 15mm report.html report.pdf

A larger top margin is useful when the first page has a tall header. A larger bottom margin can reserve room for a footer or prevent the final lines from sitting too close to the page edge. The correct values depend on your template; inspect the result instead of assuming that a command-line example will fit every design.

Make room for headers and footers

wkhtmltopdf supports header and footer options as well as separate controls for header and footer spacing. Treat those settings and the page margins as one layout system:

Rank #2
MobiPDF Lifetime - Professional PDF Editor for Windows | Edit, Sign & Convert PDFs | Best Adobe Acrobat Pro Alternative | Lifetime License
  • Edit PDFs with Ease. Modify text, images, and layouts directly within your PDF documents.
  • Convert & Organize. Export PDFs to Word, Excel, or ePub, and organize files with ease.
  • Read & Annotate. Enjoy intuitive reading modes and powerful tools to comment, highlight, and mark up PDFs.
  • Create & Manage PDFs. Create new PDFs, combine multiple files, scan documents, and compress for easy sharing.
  • Fill & Sign Forms. Complete forms and digitally sign documents with secure e-signature tools.
  1. Start with the top and bottom margins required by the printed body.
  2. Add the vertical space occupied by the header and footer in your template.
  3. Render a representative page, including the longest heading and the footer content that can occur in production.
  4. Increase the relevant page margin or reduce the corresponding header/footer spacing if content overlaps or is clipped.

The libwkhtmltox settings reference specifically warns that excessive header spacing can place a header outside the PDF. Its stated remedy is to correct the situation with margin.top. In practice, do not judge this from the command alone: open the PDF and check the first page, a middle page and the last page.

Use the official libwkhtmltox page-settings reference for the global margin and header/footer settings, and the usage documentation for the command-line switches.

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

Set margins through the libwkhtmltox API

When you embed wkhtmltopdf rather than invoking the executable, top and bottom margins are global PDF settings. Set:

Global setting Meaning Example value
margin.top Distance reserved above the page body 2cm
margin.bottom Distance reserved below the page body 2cm

The exact assignment syntax depends on the language binding you use, but the setting names are the same global PDF keys. Do not confuse these with per-page HTML CSS: they belong to the converter’s global PDF configuration. Apply them before the conversion job is created, then render and inspect the resulting document.

Verify the binary before debugging the layout

First check which executable is actually running:

wkhtmltopdf --version

-V is also accepted. Record that version with your build or deployment information. The project documentation is generated documentation, and the reviewed references do not provide a complete compatibility matrix for every version, wrapper and platform. A wrapper may also translate or discard options, so confirming the binary is an important first check.

Inspect the PDF, not just the command

Margin errors are visual. After each change, inspect:

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 #3
Scrivar PDF Pro - Organize, Edit, Compress, Convert, Merge, eSign, OCR & 30+ tools | Lifetime License
  • EVERY PDF TOOL UNLOCKED - 30+ tools in one app: edit text and images, convert, merge, split, compress, sign, OCR, redact, watermark, batch process, and more. No feature gates, no upsells, nothing held back.
  • PAY ONCE, OWN FOREVER — A one-time purchase, not a subscription. Other apps runs $240/year — Scrivar is yours for life, with free updates included.
  • UNLIMITED eSIGN, BUILT IN — Send contracts and forms for signature and track every step. Recipients sign in their browser with no account or app needed. Replace DocuSign and save hundreds a year.
  • PC, MAC, AND WEB — Install on any Win 10/11 PC or macOS 11+ Mac (Intel or Apple Silicon), or work in your browser at scrivar.com. Same tools, same account, everywhere you work.
  • OCR + FULL OFFICE CONVERSION — Turn scanned documents into searchable, selectable text, and convert PDFs to and from Word, Excel, and PowerPoint with formatting kept intact.
  • The first page, where a header is most likely to collide with the body.
  • A page containing a long paragraph, table or image.
  • The last page, where a footer or final line can be pushed beyond the bottom margin.
  • The printed or PDF-viewer page boundary, rather than only the HTML viewport.

If a change fixes one page but breaks another, use the largest header, footer or content combination that your real documents can produce as the test case.

Troubleshoot top and bottom margin problems

Symptom Likely cause Fix
The command says an option is unknown. The executable or wrapper is not the binary you expected, or it uses a different build. Run wkhtmltopdf --version, test the documented long option directly, and check the installed build’s usage output.
The header is clipped or appears outside the page. Header spacing is too large for the current top margin. Reduce header spacing or increase --margin-top/-T; the API equivalent is margin.top.
The footer overlaps body text. The body has too little reserved space at the bottom, or footer spacing is too large. Increase --margin-bottom/-B, reduce footer spacing, and render a page with the longest expected body content.
The value is rejected or behaves unexpectedly. The value has no unit or contains a typo. Use a unit-bearing value such as 20mm or 2cm.
The margins appear unchanged. The options were placed incorrectly, or a wrapper did not pass them through. Place global options before the input and output arguments, run the executable directly, and compare its PDF with the wrapper’s PDF.
Two machines render different spacing. Different binaries, versions, wrappers or platform builds may be involved. Capture wkhtmltopdf --version in diagnostics and compare the exact command and installed build before changing the margins.
Only one template is wrong. That template’s header, footer or content consumes a different amount of vertical space. Use a template-specific margin or spacing adjustment and verify it with representative first, middle and final pages.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

A repeatable margin workflow

  1. Save the exact wkhtmltopdf version with your project configuration.
  2. Measure or estimate the vertical space required by the body, header and footer.
  3. Set --margin-top and --margin-bottom with explicit units.
  4. Keep those options before the input object and output filename.
  5. Render a test PDF containing the most demanding content your production template allows.
  6. Check the first, middle and last pages and adjust the smallest margin that solves the problem.
  7. Commit the final command or global settings so another environment can reproduce the layout.

This process separates a margin problem from a source-template problem and makes future changes easier to diagnose.

Or skip the browser setup

If your goal is a clean screenshot or PDF of a live webpage rather than a local wkhtmltopdf conversion, ScreenshotNeo provides a website screenshot API and MCP server. One GET request can return PNG, JPEG, WebP or PDF output. Its capture options include paper size, margins, landscape mode and page ranges for PDF jobs, along with full-page capture, custom CSS and JavaScript, selector waits and other controls. See the ScreenshotNeo documentation for the current request options.

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)
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}`);
  • Before capture, it accepts the cookie or consent banner like a visitor and removes more than 60 known consent platforms, newsletter popups and chat widgets; each cleanup step can be turned off.
  • Only clean shots are billed. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads and cache hits cost nothing, 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.
  • The Free plan includes 1,000 shots per month with no card. Paid plans start at $5 for 3,000 shots; every feature is available on every plan, and annual billing provides two months free.

Create a free ScreenshotNeo account to use the 1,000 included monthly shots without adding a card.

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

Frequently Asked Questions

Does wkhtmltopdf document a universal recommended margin size?

No. The official references document the option syntax and settings, not a single margin that fits every printable area, header or footer. Select values for your template and verify the rendered PDF.

Can behavior be assumed identical across every wkhtmltopdf package?

No complete compatibility matrix is established by the project references. Record the output of wkhtmltopdf --version and test the exact binary, wrapper and platform you deploy.

Quick Recap

Bestseller No. 1
PDF Extra 2024| Complete PDF Reader and Editor | Create, Edit, Convert, Combine, Comment, Fill & Sign PDFs | Lifetime License | 1 Windows PC | 1 User [PC Online code]
PDF Extra 2024| Complete PDF Reader and Editor | Create, Edit, Convert, Combine, Comment, Fill & Sign PDFs | Lifetime License | 1 Windows PC | 1 User [PC Online code]
READ and Comment PDFs – Intuitive reading modes & document commenting and mark up.; CREATE, COMBINE, SCAN and COMPRESS PDFs
$99.99
Bestseller No. 2
MobiPDF Lifetime - Professional PDF Editor for Windows | Edit, Sign & Convert PDFs | Best Adobe Acrobat Pro Alternative | Lifetime License
MobiPDF Lifetime - Professional PDF Editor for Windows | Edit, Sign & Convert PDFs | Best Adobe Acrobat Pro Alternative | Lifetime License
Edit PDFs with Ease. Modify text, images, and layouts directly within your PDF documents.; Convert & Organize. Export PDFs to Word, Excel, or ePub, and organize files with ease.
$99.99

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.