Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
A4 PDF

How to Make pdfkit Render an A4 HTML Page as an A4 PDF

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

Set the paper size in the renderer, not only in your HTML. With Python’s pdfkit wrapper, pass {"page-size": "A4"} to wkhtmltopdf. With Node.js PDFKit, create the document with size: 'A4'. These packages share a name but use different APIs and rendering models.

First identify which “pdfkit” you installed

There are several projects called pdfkit. The correct setting depends on the language and package:

Runtime and package What it does A4 setting
Python pdfkit Wraps the external wkhtmltopdf HTML renderer "page-size": "A4" in the options dictionary
Node.js pdfkit Generates PDF pages directly; it does not render HTML size: 'A4' on the document or page
Ruby PDFKit Another wkhtmltopdf wrapper page_size: 'A4'

Do not copy an option from one implementation into another. In Python, an HTML file is rendered by a wkhtmltopdf executable. Node PDFKit requires you to draw text, images and other content yourself unless you add a separate HTML-to-PDF layer.

Python: render an HTML file on A4 with pdfkit

Minimal conversion

Install the Python wrapper and make sure the wkhtmltopdf executable is installed and available on your system path. Then:

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

options = {
    "page-size": "A4",
    "orientation": "Portrait",
}

pdfkit.from_file("input.html", "output.pdf", options=options)

The wrapper accepts wkhtmltopdf option names without the leading command-line dashes. Thus page-size corresponds to --page-size A4. A4 portrait is approximately 210 × 297 mm. The page-size option controls the PDF’s physical page geometry; it does not automatically make every element fit inside that page.

Convert a string or URL

import pdfkit

html = """


A4 example

A4 report

This content is rendered by wkhtmltopdf.

""" options = {"page-size": "A4", "orientation": "Portrait"} pdfkit.from_string(html, "output.pdf", options=options) # The same options can be used with a URL: # pdfkit.from_url("https://example.com", "output.pdf", options=options)

Set margins and print styling explicitly

Defaults vary by renderer build and template, so make layout-affecting choices explicit when reproducibility matters:

options = {
    "page-size": "A4",
    "orientation": "Portrait",
    "margin-top": "15mm",
    "margin-right": "15mm",
    "margin-bottom": "15mm",
    "margin-left": "15mm",
    "print-media-type": "",
    "zoom": "1",
}
pdfkit.from_file("input.html", "output.pdf", options=options)

In wkhtmltopdf, a valueless switch such as --print-media-type is represented by an empty string in the Python options dictionary. Use an explicit print stylesheet when your screen and print layouts differ:

<style>
@media print {
  body { font-size: 11pt; }
  .screen-only { display: none; }
}
</style>

Margins reduce the usable content area. A large zoom can make content appear clipped or force unexpected page breaks; a small zoom can make text illegibly small. Adjust these only after confirming that the PDF page itself is A4.

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

Use a specific wkhtmltopdf executable

If the binary is not on PATH, or you need a known build, pass a configuration object:

import pdfkit

config = pdfkit.configuration(wkhtmltopdf="/absolute/path/to/wkhtmltopdf")
pdfkit.from_file(
    "input.html",
    "output.pdf",
    options={"page-size": "A4"},
    configuration=config,
    verbose=True,
)

verbose=True exposes renderer output, which is useful for missing assets, JavaScript errors and executable problems. Python pdfkit’s project documentation marks the wrapper deprecated, and it notes that some distribution packages are built without all of wkhtmltopdf’s Qt patches. Check the actual executable and version deployed in production instead of assuming two installations behave identically.

Node.js PDFKit: request A4 directly

Node PDFKit does not consume an HTML document as wkhtmltopdf does. It creates PDF pages directly. Its documented default is Letter, so request A4 explicitly:

const PDFDocument = require('pdfkit');
const fs = require('node:fs');

const doc = new PDFDocument({ size: 'A4', margin: 50 });
doc.pipe(fs.createWriteStream('output.pdf'));
doc.fontSize(24).text('A4 report');
doc.moveDown().fontSize(12).text('Content drawn by Node PDFKit.');
doc.end();

You can select A4 for an individual page as well:

doc.addPage({ size: 'A4', layout: 'portrait' });

PDFKit documents A4 as 595.28 × 841.89 PDF points in portrait orientation. Landscape reverses those dimensions. If your source is HTML, use an HTML-capable renderer instead of expecting PDFKit’s size option to parse CSS.

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

Ruby PDFKit

Ruby’s PDFKit wrapper also delegates to wkhtmltopdf, but its option naming follows Ruby conventions:

kit = PDFKit.new(html, page_size: 'A4', orientation: 'Portrait')
File.binwrite('output.pdf', kit.to_pdf)

Confirm the exact gem version and its configuration syntax before deploying; options from Python pdfkit and Node PDFKit are not interchangeable.

Verify that the output is really A4

  1. Open the generated PDF in a viewer that displays document properties.
  2. Check the page dimensions, not merely the zoom percentage shown on screen. A portrait A4 page is 210 × 297 mm, or 595.28 × 841.89 points.
  3. If dimensions are correct but content is clipped, investigate margins, orientation, zoom, print media and CSS page breaks separately.
  4. For automated checks, inspect the PDF’s page box with a PDF parser or a command-line inspection tool in your build pipeline.

A browser preview can look correct while the PDF differs because wkhtmltopdf uses its own rendering engine, font availability, viewport and print rules.

CSS and pagination details that affect an A4 result

Define print dimensions carefully

Use physical units for print-oriented rules:

@page {
  size: A4 portrait;
  margin: 15mm;
}

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

h1, h2 {
  page-break-after: avoid;
}

The renderer’s command-line page settings still determine the final PDF geometry. CSS can improve pagination, but it cannot repair an incorrectly configured executable or override every renderer limitation.

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

Account for external resources

  • Use absolute, reachable URLs or configure the correct working directory for local assets.
  • Ensure fonts are installed in the conversion environment; a fallback font changes line wrapping and page count.
  • Wait for JavaScript-generated content when your wkhtmltopdf build and wrapper support an appropriate delay or JavaScript wait option.
  • Test images at their actual print resolution; very wide images can expand or overflow a content box.

Troubleshooting common failures

The PDF is Letter instead of A4

Confirm that you are using the Python wrapper, that the dictionary key is exactly page-size, and that the options dictionary is passed to the same conversion call that creates the PDF. Print the configured executable path and run that binary’s help or version command. A different binary on PATH may be receiving the request.

A4 dimensions are correct but content is cut off

This is a layout problem, not a paper-size problem. Reduce margins or zoom, select the intended orientation, inspect fixed-width elements, and review print CSS. Replace rigid pixel widths with responsive or physical units where possible.

Images, fonts or styles are missing

Check the renderer’s verbose output, asset URLs and file permissions. Local-file access restrictions, blocked remote resources and unavailable fonts are common causes. Test with a self-contained HTML file to distinguish asset failures from pagination issues.

Rank #4
Sale
Funny Coding I Know HTML How To Meet Ladies T-Shirt
  • Funny saying for any front-end developer, web developer, computer programmer, computer systems engineer, mobile app developer, software developer, or code lover who likes to code, make funny programming jokes, and take memorable photos.
  • Wear it proudly at International Programmers' Day, school, coding classes, or coding communities! It also makes a funny present for a computer programming lover friend.
  • Lightweight, Classic fit, Double-needle sleeve and bottom hem

The command cannot find wkhtmltopdf

Install the executable for the target operating system or pass its absolute path through pdfkit.configuration(). Keep the same binary and version in development, CI and production when identical output matters.

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

Headers, footers or outlines behave differently across machines

Distribution-provided wkhtmltopdf builds may omit Qt patches or other functionality. Record the binary version, package source and operating system, then test the exact production build. Do not assume a successful conversion means every optional feature is supported.

HTML looks good in a browser but the PDF looks bad

Browsers and wkhtmltopdf are different engines. Add print-specific CSS, verify fonts and asset loading, set an appropriate viewport or zoom, and inspect page breaks. A 2024 public discussion described this symptom, but it is anecdotal and does not establish how often it occurs.

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

Performance, reliability and cost considerations

Rendering a URL starts an external process and may load remote assets, so conversion time depends on page complexity, network access and JavaScript. For repeatable builds, pin the renderer, keep assets local or reliably hosted, set an application timeout, and retain verbose logs for failed jobs. Generate to a temporary file and move it into place only after conversion succeeds, preventing partial PDFs from being published.

Page size itself has negligible impact compared with image decoding, JavaScript and large documents. If a report contains many pages, split work into bounded jobs and validate each output’s page boxes. The Python wrapper is deprecated according to its project documentation, so evaluate a maintained renderer if long-term security or modern CSS support is a requirement; changing renderers requires re-testing pagination and fonts.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
I Know HTML How To Meet Ladies Funny Programming Language T-Shirt
  • Programming Language Lover Code Apparel. App or Web Design and Development Expert Funny Dress. Best Valentines Idea For Coding Lover. HTML Code or Meaning Costume
  • Funny I Know HTML - How To Meet Ladies Computer Programmer Quotes
  • Lightweight, Classic fit, Double-needle sleeve and bottom hem

Or skip the browser setup

ScreenshotNeo provides a website screenshot API and MCP server when you need an image or PDF of a URL without installing a browser or wkhtmltopdf. A single request can return PNG, JPEG, WebP or PDF, with A4 paper settings available for PDF captures.

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

See the ScreenshotNeo documentation for PDF parameters such as paper size, margins, landscape mode and page ranges. Before capture, it can accept cookie or consent banners and remove more than 60 known consent platforms, newsletter popups and chat widgets; each step can be disabled. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads and cache hits are not billed, and response headers identify the page verdict and billing status.

For 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)

For 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}`);

Its 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. Sign up for the free plan to try it.

Frequently Asked Questions

Does setting @page { size: A4 } alone guarantee an A4 PDF?

No. Set the renderer’s page option as well, then verify the generated PDF’s page dimensions. CSS mainly controls print layout and pagination.

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.

Can Node PDFKit convert my existing HTML automatically?

No. Node PDFKit draws PDF content directly. Use an HTML-capable renderer if preserving HTML and CSS is the requirement.

Which A4 dimensions should an automated test expect?

Portrait A4 is 595.28 × 841.89 PDF points, equivalent to 210 × 297 mm.

Quick Recap

Bestseller No. 2
SaleBestseller No. 4
Funny Coding I Know HTML How To Meet Ladies T-Shirt
Funny Coding I Know HTML How To Meet Ladies T-Shirt
Lightweight, Classic fit, Double-needle sleeve and bottom hem
$14.27
Bestseller No. 5
I Know HTML How To Meet Ladies Funny Programming Language T-Shirt
I Know HTML How To Meet Ladies Funny Programming Language T-Shirt
Funny I Know HTML - How To Meet Ladies Computer Programmer Quotes; Lightweight, Classic fit, Double-needle sleeve and bottom hem
$19.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.

Leave a Reply

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

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

Read next

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