How to convert HTML to PDF: 10 best tools compared
Table of contents
Pick the right tool to convert HTML to PDF based on what you need to deliver:
Secure, fillable PDFs at scale — Nutrient Document Engine converts HTML to PDF with form fields, digital signatures, encryption, and workflow automation via a REST API.
JavaScript-heavy pages to PDF — Puppeteer (Chrome) or Playwright (Chromium, Firefox, WebKit) render dynamic content server-side before exporting.
Quick browser-side export — jsPDF or html2pdf.js generate PDFs client-side with no server required.
Python backend — WeasyPrint renders HTML/CSS precisely and integrates with Django and Flask.
PHP backend — Dompdf converts HTML to PDF inside Laravel, Symfony, and other PHP frameworks.
CLI scripting — wkhtmltopdf converts HTML from the command line using WebKit.
Programmatic PDF building — pdfmake (JSON schema) or PDFKit (Node.js API) build PDFs from code, not markup.
To convert an HTML file to PDF, you can use open source tools like wkhtmltopdf, Puppeteer, or jsPDF for simple jobs. For enterprise workflows requiring form conversion, digital signatures, and security, Nutrient Document Engine is the best way to convert HTML to PDF at scale.
Common problems when you convert HTML to PDF include broken layouts, missing styles, and limited security features. This guide compares 10 tools — from browser libraries to enterprise processors — so you can pick the right one for your project.
1. Convert HTML to PDF with Nutrient Document Engine
Nutrient Document Engine handles HTML-to-PDF conversion for enterprise applications. This server-side toolkit handles PDF generation, editing, OCR, redaction, annotation, signing, and real-time collaboration. Run it headless as a backend service, or pair it with Nutrient’s web, mobile, or desktop SDKs.
HTML-to-PDF conversion
Document Engine converts HTML to PDF by accepting an HTML source (as a file or string) and processing it through a rendering engine that supports HTML5 and CSS3. It handles advanced layouts with flexbox, grid, media queries, custom fonts, and interactive elements. You send your HTML content — along with a JSON instructions object — to the /api/build endpoint. The engine returns a PDF that mirrors your original HTML, including headers, footers, watermarks, and fillable form fields.
Example with curl:
curl -X POST http://localhost:5000/api/build \ -H "Authorization: Token token=<API token>" \ -F page.html=@/path/to/page.html \ -F instructions='{ "parts": [{ "html": "page.html" }] }' \ -o result.pdfThis command uploads your HTML file and instructions to Document Engine, which returns the generated PDF. Because the rendering engine is Chromium-based, you can preview your HTML in Chrome to check the output before generating it.
Key features beyond HTML-to-PDF conversion
- Form conversion — Turn HTML forms into fillable PDFs your users can complete, sign, and submit.
- Workflow automation — Reduce multistep processes to a single API call — merge files, add watermarks, and generate PDFs in one request.
- Flexible deployment — Self-host on your infrastructure to meet compliance requirements, or use Nutrient’s managed cloud to ship faster.
- Wide format support — Accept Office files, images, and HTML — deliver consistent PDFs across formats.
- Scalable and reliable — Process large files, high-volume jobs, and concurrent requests with high availability.
Use cases
- Ship invoices, reports, and certificates to customers automatically — no manual PDF creation.
- Let users fill out web forms and receive completed, signed PDFs they can download or share.
- Add secure, compliant PDF generation to your application without building a rendering pipeline.
Nutrient has SDKs for JavaScript, Python, Ruby, PHP, Java, and .NET. See the PDF SDK page for the full list.
In practice, teams use open source tools for small internal scripts or low-risk exports and choose Nutrient Document Engine when HTML-to-PDF conversion is part of a production workflow (invoices, statements, contracts, reports) where layout, security, and reliability matter.
Start a free trial or talk to Sales.
2. Convert HTML to PDF using wkhtmltopdf

wkhtmltopdf(opens in a new tab) is a command-line tool that uses WebKit to convert HTML to PDF. It handles complex webpages with advanced CSS and JavaScript.
Key features
- HTML5 and CSS3 support — Converts modern webpages with HTML5 and CSS3 features.
- Complex layout handling — Manages multicolumn designs, embedded media, and other complex layouts.
- Customization — Offers options for page sizes, margins, headers, footers, and more.
- JavaScript execution — Executes JavaScript before rendering, ensuring dynamic content is included.
Limitations
- The project is no longer actively maintained (archived since 2023).
- Uses an older WebKit engine, so modern CSS (flexbox, grid) may not render correctly.
- No support for fillable forms, digital signatures, or encryption.
Use cases
- Server-side PDF generation in web applications
- Automated PDF creation from dynamic content
- Print-ready documents
Check out the following blog posts to learn more about how to use wkhtmltopdf:
- Python HTML to PDF: Convert HTML to PDF using wkhtmltopdf
- How to convert HTML to PDF in C# using wkhtmltopdf
wkhtmltopdf handles basic conversion well, but it can’t produce fillable forms, apply digital signatures, or encrypt output. If you need those capabilities, Nutrient Document Engine delivers them out of the box.
3. Convert HTML to PDF using Puppeteer

Puppeteer(opens in a new tab) is a Node.js library from Google that controls Chrome or Chromium. It renders JavaScript-heavy pages before converting them to PDF.
Key features
- Modern web standards support — Handles JavaScript, CSS, and HTML5, so it fully renders complex pages.
- Dynamic content rendering — Renders single-page applications (SPAs) and other dynamic content.
- Customizable PDF output — Controls headers, footers, and page layout in PDF output.
- Automation integration — Integrates with automation workflows and CI/CD pipelines.
Limitations
- Requires a Chromium binary (~300 MB), which increases deployment size.
- Chrome-only — no Firefox or WebKit support.
- Cannot produce fillable forms, signatures, or encrypted PDFs.
Example
const puppeteer = require('puppeteer');
(async () => { const browser = await puppeteer.launch(); const page = await browser.newPage(); await page.goto('https://example.com', { waitUntil: 'networkidle0', }); await page.pdf({ path: 'output.pdf', format: 'A4', printBackground: true, }); await browser.close();})();Use cases
- PDFs from JavaScript-rendered pages
- CI/CD pipeline automation
- Converting SPAs and interactive web apps to static PDFs
4. Convert HTML to PDF using Playwright

Playwright(opens in a new tab) is a Node.js library from Microsoft that automates Chromium, Firefox, and WebKit. Unlike Puppeteer, it supports multiple browsers.
Key features
- Cross-browser support — Automates Chromium, Firefox, and WebKit.
- JavaScript-heavy page handling — Renders complex, JavaScript-heavy pages.
- PDF layout control — Supports custom page sizes and margins.
- Integration with testing frameworks — Works with end-to-end testing frameworks for PDF generation.
Limitations
- Requires downloading browser binaries (~hundreds of MB per browser).
- PDF generation only works with Chromium — Firefox and WebKit don’t support
page.pdf(). - No built-in forms, signatures, or encryption support.
Example
const { chromium } = require('playwright');
(async () => { const browser = await chromium.launch(); const page = await browser.newPage(); await page.goto('https://example.com', { waitUntil: 'networkidle', }); await page.pdf({ path: 'output.pdf', format: 'A4', margin: { top: '1cm', bottom: '1cm' }, }); await browser.close();})();Use cases
- Cross-browser PDF generation
- Converting SPAs and complex webpages
- Automated testing workflows with PDF output
Check out the following blog post to learn more about how to use Playwright:
5. Convert HTML to PDF using jsPDF

jsPDF(opens in a new tab) is a JavaScript library for client-side PDF generation. It creates PDFs directly in the browser without a server and is best for simple layouts and static content.
Key features
- Basic PDF creation — Supports text, images, and shapes.
- User interaction — Allows for annotations and other interactive features.
- Extensible — Plugins add HTML rendering, extra fonts, and other features.
- Basic styling — Offers basic styling through built-in methods and manual HTML parsing.
- Customizable page orientation — Supports portrait and landscape orientation, custom page widths, and margins.
Limitations
- Poor support for complex CSS layouts — flexbox and grid won’t render.
- Relies on html2canvas for HTML rendering, which rasterizes content (no selectable text in the PDF).
- Large or multipage documents can hit browser memory limits.
Example
import { jsPDF } from 'jspdf';import html2canvas from 'html2canvas';
const element = document.getElementById('content');html2canvas(element).then((canvas) => { const imgData = canvas.toDataURL('image/png'); const pdf = new jsPDF('p', 'mm', 'a4'); const width = pdf.internal.pageSize.getWidth(); const height = (canvas.height * width) / canvas.width; pdf.addImage(imgData, 'PNG', 0, 0, width, height); pdf.save('output.pdf');});Use cases
- Exporting HTML forms or content as PDFs
- Simple reports generated in the browser
- Client-side PDF generation without a server
Check out the following blog posts to learn more about how to use jsPDF:
- How to convert HTML to PDF in React
- Generate PDFs in Salesforce with Lightning web components
- Generate a PDF from HTML with Vue.js
- How to use jsPDF and Angular to generate PDFs
- How to export to PDF using React
6. Convert HTML to PDF using html2pdf.js

html2pdf.js(opens in a new tab) combines jsPDF and html2canvas for browser-side HTML-to-PDF conversion. It handles basic styling and images but struggles with complex layouts.
Key features
- HTML rendering with PDF generation — Combines HTML rendering with jsPDF’s PDF generation capabilities.
- Image support — Supports image conversion and embedding.
- Basic CSS styling — Allows for basic CSS styling and layouts.
- Client-side operation — Runs entirely in the browser, which suits single-page applications (SPAs).
Limitations
- Rasterizes HTML via html2canvas, so text in the PDF isn’t selectable or searchable.
- Breaks on complex CSS (grid, flexbox, sticky positioning).
- Output quality varies across browsers and screen resolutions.
Use cases
- Downloadable PDFs from user-generated content
- Exporting webpage sections
- Lightweight browser-based PDF generation
Check out the following blog posts to learn more about how to use html2pdf.js:
- Generate a PDF from HTML with Vue.js
- How to convert HTML to PDF in React using html2pdf
- How to convert HTML to PDF using html2pdf
- How to convert HTML to PDF with JavaScript
Client-side tools like html2pdf.js work for quick exports, but the output quality depends on the browser. For consistent, production-grade PDFs with form fields and security, Nutrient Document Engine gives you server-side control over the output.
7. Convert HTML to PDF using WeasyPrint

WeasyPrint(opens in a new tab) is a Python rendering engine that converts HTML and CSS to PDF. It supports modern web standards and handles complex layouts well.
Key features
- Modern web standards support — Supports HTML5, CSS3, and SVG.
- Complex layouts — Accurately renders complex layouts, including multipage documents, footnotes, and page numbers.
- Framework integration — Integrates with Django and Flask.
- Automation — Includes a command-line interface for scripting.
Limitations
- No JavaScript execution — dynamic content won’t render.
- System dependencies (Cairo, Pango) can complicate deployment.
- Limited CSS3 support compared to browser-based tools.
Example
from weasyprint import HTML
# Convert an HTML file to PDF.HTML('page.html').write_pdf('output.pdf')
# Or convert a URL directly.HTML('https://example.com').write_pdf('output.pdf')
# Or pass an HTML string.HTML(string='<h1>Hello, PDF</h1>').write_pdf('output.pdf')Use cases
- Server-side PDF generation for Django and Flask apps
- Automated report generation
- Print-ready documents with complex layouts
Check out the following blog post to learn more about how to use WeasyPrint:
8. Convert HTML to PDF using pdfmake

pdfmake(opens in a new tab) generates PDFs in both the browser and Node.js using a declarative JSON structure. It’s good for dynamic, programmatically generated documents.
Key features
- Declarative structure — Define PDF layout using a hierarchical JSON structure.
- Rich content support — Supports text, images, tables, and vector graphics.
- Dynamic content — Includes support for loops, conditions, and external data.
- Customization — Provides full control over PDF structure and content.
Limitations
- Does not accept HTML directly — you must convert HTML to pdfmake’s JSON schema first.
- No CSS support; all styling is done through pdfmake’s own properties.
- Complex layouts require significant manual configuration.
Use cases
- Dynamic invoices, reports, and forms
- Custom PDFs with specific layout rules
- Works in both browser and Node.js
Check out the following blog post to learn more about how to use pdfmake:
9. Convert HTML to PDF using PDFKit
PDFKit(opens in a new tab) is a Node.js library for generating PDFs programmatically. It supports text, images, vector graphics, and encryption.
Key features
- Advanced PDF features — Supports embedded fonts, encryption, and access controls.
- Precise layout control — Gives fine-grained control over layout, content, and structure.
- Streaming support — Streams large documents to avoid memory limits.
- Node.js integration — Works with standard Node.js modules.
Limitations
- No HTML/CSS parsing — you build PDFs programmatically with API calls, not from markup.
- Steep learning curve for complex layouts (manual x/y positioning).
- No built-in digital signatures.
Use cases
- Server-side PDF generation
- Complex reports, invoices, and catalogs
- Large documents with streaming support
Check out the following blog post to learn more about how to convert HTML to PDF with JavaScript:
10. Convert HTML to PDF using Dompdf

Dompdf(opens in a new tab) is a PHP library that converts HTML and CSS to PDF. It integrates with Laravel, Symfony, and other PHP frameworks.
Key features
- CSS2.1 and CSS3 support — Supports most CSS2.1 properties and some CSS3 properties.
- HTML5 rendering — Renders HTML5, including inline PHP and complex tables.
- Custom fonts and styles — Provides support for custom fonts and styles.
Limitations
- No JavaScript execution — only static HTML and CSS.
- Limited CSS3 support (no flexbox or grid).
- Slow on large or image-heavy documents.
Use cases
- PHP-based PDF generation
- Converting web forms and reports to PDF
- Automated PDF creation in Laravel/Symfony apps
If your PHP application needs digital signatures, encryption, or fillable forms in the generated PDFs, Nutrient Document Engine provides a REST API you can call from PHP or any other language.
Comparison: Best tools to convert HTML to PDF
| Library | Language | License | Fillable forms | Signatures | Encryption | JavaScript support |
|---|---|---|---|---|---|---|
| wkhtmltopdf | Command line | Open source (LGPLv3) | No | No | No | Yes |
| Puppeteer | Node.js | Open source (Apache 2) | No | No | No | Yes |
| Playwright | Node.js | Open source (Apache 2) | No | No | No | Yes |
| jsPDF | JavaScript | Open source (MIT) | No | No | No | N/A (client-side) |
| html2pdf.js | JavaScript | Open source (MIT) | No | No | No | N/A (client-side) |
| WeasyPrint | Python | Open source (BSD) | No | No | No | No |
| pdfmake | JavaScript | Open source (MIT) | No | No | No | N/A (JSON schema) |
| PDFKit | Node.js | Open source (MIT) | No | No | Yes | N/A (programmatic) |
| Dompdf | PHP | Open source (LGPL) | No | No | No | No |
| Nutrient Document Engine | REST API | Commercial (free trial) | Yes | Yes | Yes | Yes |
Open source options handle one-off jobs and internal tooling well. For recurring or compliance-sensitive workflows, Nutrient Document Engine is the better fit.
Enterprise consideration: Most open source tools can’t produce fillable forms, encrypt output, or meet compliance requirements. Nutrient Document Engine delivers all three, backed by support and SLA terms — so your team can deliver secure PDFs without maintaining the infrastructure.
How to choose the right tool to convert HTML to PDF
The right tool to convert HTML to PDF depends on your project requirements.
1. Complexity of content
If your HTML includes complex layouts or dynamic elements, frameworks like Playwright or pdfmake can help for code-level control. For pixel-perfect output on invoices, statements, and reports, Nutrient Document Engine uses Chromium-based rendering and adds forms, signatures, and encryption.
2. Forms support
If your users need to fill out, sign, and return PDFs, Nutrient Document Engine automatically converts HTML <input> elements into fillable PDF form fields — so your team doesn’t have to build a separate forms pipeline.
Other tools generate static PDFs. Only Nutrient Document Engine turns HTML forms into interactive, fillable PDFs in a single API call.
3. Performance and security
Server-side tools handle large or confidential documents better than client-side libraries. Teams often start with open source and switch to Nutrient Document Engine when they need encrypted output, audit trails, or guaranteed uptime for customer-facing PDF workflows.
Best practices for HTML-to-PDF conversion
Regardless of which tool you choose, these practices help you produce reliable PDFs from HTML.
Use print-specific CSS
Add a @media print stylesheet to control how your HTML renders in PDF output. Remove navigation, footers, and ads; set explicit page margins; and force background colors to print:
@media print { nav, footer, .no-print { display: none; } body { margin: 0; font-size: 12pt; } * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }}Set explicit page dimensions
Most tools default to US Letter. If your audience expects A4, set it explicitly. In Puppeteer and Playwright, pass format: 'A4'. In CSS, use @page { size: A4; margin: 2cm; }.
Optimize images before conversion
Large images slow down conversion and bloat PDF file size. Compress images to web-quality resolution (150 DPI is enough for screen PDFs; use 300 DPI for print). Prefer JPEG for photos and PNG for diagrams.
Wait for dynamic content to load
If your page loads data asynchronously, make sure the converter waits before generating the PDF. In Puppeteer, use waitUntil: 'networkidle0'. In Playwright, use waitUntil: 'networkidle'. Skipping this step is the most common cause of blank or incomplete PDFs.
Test with real content
Don’t test with “Lorem ipsum” and expect production HTML to look the same. Long headings, oversized images, and multipage tables all break layouts. Test with your actual data before going to production.
Handle page breaks
Use page-break-before, page-break-after, and page-break-inside: avoid in CSS to prevent tables, images, and headings from splitting across pages.
Nutrient Document Engine supports all of these practices out of the box — including print CSS, custom page sizes, and automatic page-break handling — and adds features like headers, footers, and watermarks via its instructions API.
Conclusion
If you need to convert HTML to PDF for side projects or simple exports, the open source tools in this list work well. When your team needs to deliver secure, fillable PDFs at scale — invoices, signable contracts, and compliant reports — Nutrient Document Engine handles it without requiring a custom pipeline. Start a free trial or talk to our Sales team.
FAQ
For enterprise applications, Nutrient Document Engine is the strongest option to convert HTML to PDF — it includes form conversion, digital signatures, and encryption, and it scales to high-volume workloads. For simple projects, use wkhtmltopdf for server-side generation, Puppeteer for JavaScript-heavy pages, or jsPDF for basic client-side needs.
Most open source tools can’t. Nutrient Document Engine lets you convert HTML to PDF with encryption, digital signatures, redaction, and compliance features for business applications handling sensitive documents.
Use Puppeteer or Playwright for server-side Node.js, or jsPDF/html2pdf.js for client-side browser conversion. For enterprise needs, Nutrient Document Engine provides a REST API that works from any JavaScript environment.
Only Nutrient Document Engine automatically converts HTML form elements into fillable PDF form fields when you convert HTML to PDF. Other tools generate static PDFs.
Use WeasyPrint for open source Python HTML-to-PDF conversion. For enterprise features like forms and signatures, use Nutrient Document Engine’s REST API from Python.