DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
HTML to PDF

How to Convert HTML to PDF Without Rendering a Webpage

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

To convert HTML to PDF without launching a full browser, use a document-oriented layout engine such as WeasyPrint. It parses HTML and CSS into paginated output rather than opening Chrome or Firefox. For Python services that generate reports, invoices, and other static documents, WeasyPrint offers a direct API; Prince XML is a commercial alternative for print-focused publishing. Be precise about the requirement: “headless” means no visible browser window, while “browserless” means no full browser rendering engine.

What “without rendering the webpage” means

HTML must be laid out somehow before it can become a PDF. In this context, “without rendering the webpage” usually means avoiding a full browser runtime such as Chrome or Firefox—not skipping layout altogether. A document engine reads the HTML, applies the CSS and lays the content onto PDF pages. That makes it useful when you already have the HTML and want a document, rather than a screenshot of an interactive website.

This distinction matters when choosing a tool. A headless browser still renders a page with a browser engine; it simply does so without opening a visible window. A document-oriented converter can avoid that full browser dependency, but it may not reproduce browser-specific behavior or execute the JavaScript your page needs.

Choose an engine for your HTML and output needs

Tool Rendering approach Good fit Trade-offs to check
WeasyPrint Document-oriented HTML, CSS and SVG engine; does not rely on a full browser engine. Python applications creating reports, invoices, certificates and other paged documents. Design for the CSS and PDF features it supports. Do not assume browser JavaScript behavior will be available.
Prince XML HTML/XML formatter that applies CSS to produce PDFs. Print-oriented publishing where its paged-media capabilities or commercial support justify the product. It is commercial software; verify current licensing and deployment terms for your use.
wkhtmltopdf Headless command-line renderer using Qt WebKit. Legacy templates or deployments that depend on its WebKit rendering behavior, or cases where no visible browser window is the actual requirement. It is not browserless in the strict sense: it uses a browser rendering engine.

The official project descriptions establish the tools’ architectures and capabilities, but do not provide a comparable speed, memory-use or fidelity benchmark. Choose from the requirements of your templates, then measure your own workload rather than relying on an unsupported general ranking.

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

Use WeasyPrint for server-generated documents

WeasyPrint is the clearest open-source Python choice in this comparison when your input is already-materialized HTML and CSS. Its project describes generating structured documents without relying on a full browser engine, and its documentation covers pagination, page margins, headers and footers. It exposes a Python API, so a web service can generate PDF bytes without launching a separate visible browser.

Consider Prince for demanding print layouts

Prince converts HTML or XML by applying CSS and supports local or remote input, stylesheets, optional scripts and combining inputs. Its documentation also describes language wrappers. That makes it an option to evaluate when a publishing workflow needs advanced print-specific control or commercial support. Check the current license and supported deployment model before adopting it; terms are not established here.

Keep wkhtmltopdf for compatible legacy work

The wkhtmltopdf project calls it a headless command-line tool using Qt WebKit. “Headless” can satisfy a requirement not to show a browser window, but it does not meet a strict requirement to avoid a browser rendering engine. If a legacy template was built around WebKit behavior, test it against the version and environment you deploy rather than treating the tool as interchangeable with a document engine.

Convert HTML to PDF with WeasyPrint in Python

Install WeasyPrint using the installation instructions for your operating system and Python environment. The project has system-level dependencies, so follow its current install guidance for the platform you deploy; do not assume a package installation alone covers every host. Once installed, pass your HTML to HTML, provide a base URL for relative assets, then call write_pdf().

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.
from weasyprint import HTML

html_string = """
<!doctype html>
<html>
  <head><meta charset="utf-8"><title>Report</title></head>
  <body><h1>Monthly report</h1><p>Generated from HTML.</p></body>
</html>
"""

# Use the directory or URL that relative assets should resolve against.
base_url = "file:///srv/app/templates/"
pdf_bytes = HTML(string=html_string, base_url=base_url).write_pdf()

with open("output.pdf", "wb") as pdf_file:
    pdf_file.write(pdf_bytes)

With no output argument, the documented write_pdf() method returns the PDF as bytes in memory. That suits an application that needs to stream a response or store the result itself. If you prefer a file path, the WeasyPrint first-steps documentation also shows calling HTML('https://weasyprint.org/').write_pdf('/tmp/weasyprint-website.pdf'). Use an explicit, stable base_url when generating from a string or template so relative stylesheets, images and fonts resolve from the intended location.

Add print CSS before adjusting the HTML

Web layouts are not automatically good page layouts. Add a print stylesheet that establishes the paper size and margins, and decide where page breaks are acceptable. Keep long tables, headings and paragraphs from splitting awkwardly where the engine supports the relevant CSS behavior.

@page {
  size: A4;
  margin: 18mm 16mm;
}

@media print {
  h1, h2 { break-after: avoid; }
  table, figure { break-inside: avoid; }
  .page-break { break-before: page; }
}

Use the page dimensions and margins appropriate to your document; A4 above is an example, not a universal requirement. WeasyPrint’s documentation cautions that every combination of HTML, CSS and PDF features is not guaranteed. Keep templates within supported specifications and check the generated result with representative content, especially after changing styles or the converter version.

Other command-line options

Prince XML

A minimal Prince invocation takes an HTML input and writes a PDF:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
prince input.html -o output.pdf

Prince’s documentation also describes applying optional stylesheets and scripts, reading local or remote HTML/XML, and combining multiple inputs. Adapt the command to the installed version and the exact inputs your workflow needs. Scripts can be relevant when content must be prepared before pagination, but if your process depends on browser-only JavaScript, test the result rather than assuming the optional script feature behaves like a full browser.

wkhtmltopdf

The project’s example is:

wkhtmltopdf http://example.com output.pdf

This is a headless conversion command, not a browserless one: the project identifies Qt WebKit as its rendering engine. Use it when compatibility with an existing WebKit-based workflow matters or when the only constraint is avoiding a visible browser window. Exclude it if policy or architecture requires that no browser rendering engine run.

Make output reliable and predictable

Materialize dynamic content first

If a page depends on JavaScript to insert text, prices, charts or tables, a document engine that does not run the required scripts may produce an incomplete PDF. Prefer rendering the data into the HTML on the server before conversion. Prince documents optional script execution, but that does not establish that arbitrary browser-dependent applications will behave identically there. When JavaScript is essential, test the exact template and engine; if it needs a full browser, the strict browserless requirement and the page’s behavior may be incompatible.

Resolve assets explicitly

Relative paths only work when the converter can resolve them. Provide a correct base URL or use accessible absolute paths, and make sure images, stylesheets and font files are available to the conversion process. A path that works from a developer’s browser may not exist inside a container or on a production host.

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

Design for page boundaries

Screen CSS often assumes a continuous canvas. Define print rules for page size, margins, breaks and content that should stay together. Inspect long tables, headings at the bottom of a page, and documents whose text or data can grow. Use real examples at their largest expected size; a short sample will not reveal every pagination problem.

Control external dependencies

Fetching remote fonts, images or stylesheets during conversion can make output dependent on network availability and on changes at the remote host. It can also expose the converter to URLs that your application did not intend it to fetch. For reproducible documents, fetch and validate required assets in your application, then make the approved files available to the converter. Limit what untrusted HTML can access, particularly when the process can read local files or request internal network resources.

Validate PDFs and troubleshoot common failures

After conversion, validate more than whether a PDF file exists. Extract text or search within it, inspect links and fonts, check page count, and visually review examples that contain long tables, images and page breaks. No universal performance or fidelity result is established across these engines, so collect measurements on your own representative inputs if those characteristics matter.

Symptom Likely cause What to check or change
Images, fonts or styles are missing Relative URLs cannot be resolved, a file is inaccessible, or remote assets could not be fetched. Set an explicit base URL, verify paths from the converter’s runtime environment, and make required resources available locally when reproducibility matters.
JavaScript-created content is absent The chosen document engine does not execute the page’s required script behavior. Render the content into HTML before conversion, or verify that a suitable engine’s documented script support covers the exact case.
Text or tables break badly across pages Screen-oriented CSS has no suitable print pagination rules. Set page size and margins, add intentional break rules, and test long-content examples.
Output differs between runs Remote assets, changing source HTML, or environment-dependent fonts and paths may vary. Keep inputs and assets stable, record the template and engine version used, and compare generated PDFs in regression tests.
File generation fails on deployment but works locally System dependencies, file permissions, or accessible paths differ in the deployment environment. Follow the engine’s installation guidance for that operating system and verify dependencies and permissions in the actual runtime image.
The result is a PDF but not a faithful interactive page A PDF is a paged document, not a live webpage; browser-specific layout or dynamic behavior may not be reproduced. Decide whether the requirement is a paginated document or a capture of the rendered site, then choose an architecture that matches it.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Performance, deployment and cost considerations

The available product documentation does not establish a comparable speed, memory or fidelity benchmark for these converters, so there is no evidence-based universal fastest choice here. Measure the actual templates that matter, including asset-heavy documents and the largest expected tables. Track conversion duration, resource use, failures and output validity in your own environment.

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

For reliability, pin or record the converter version, use stable inputs, keep assets accessible, and maintain a small set of representative PDFs as regression checks. For cost, compare operational and licensing needs rather than assuming all tools have the same model: WeasyPrint and wkhtmltopdf are described as open-source projects, while Prince is commercial. Verify current licensing and support terms directly before deployment.

Or skip the browser setup

If what you need is a PDF or image capture of a rendered website—not a strict browserless conversion of existing HTML—ScreenshotNeo provides a website screenshot API and MCP server. One GET request can return PNG, JPEG, WebP or PDF output. It does render a website to capture it, so it is an alternative when you want to avoid managing browser setup, not a way to satisfy a requirement that forbids browser rendering.

Example cURL call for a PDF capture:

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

See the ScreenshotNeo API documentation for parameters and output options. Its consent-banner, newsletter-popup and chat-widget cleanup steps can be turned off individually; bot checks, blank pages, timeouts, failed loads and cache hits are not billed, and response headers identify the page verdict and billing status. The MCP server offers take_screenshot, get_page_info and capture_pdf for Claude, Cursor and other MCP clients. The Free plan includes 1,000 shots per month without a card; paid plans start at $5 for 3,000 shots. Sign up for 1,000 free screenshots a month, with no card required.

Frequently Asked Questions

Will a browserless converter run my page’s JavaScript?

Do not assume it will. If the HTML depends on scripts, render the required data into the HTML before conversion or test an engine whose documented script support fits the specific workflow.

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

Can I convert HTML that is stored as a Python string?

Yes. WeasyPrint accepts HTML as a string through its Python API; provide a base URL when the markup uses relative assets.

Does wkhtmltopdf meet a policy that prohibits browser engines?

No. Its project identifies Qt WebKit as its rendering engine, even though wkhtmltopdf runs headlessly.

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 *

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.

Read next

Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

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.