Skip to main content
The HTML to PDF tool converts any HTML file into a pixel-perfect PDF. Use your own HTML and CSS — including frameworks like Tailwind CSS or Bootstrap — and get a print-ready document with customizable page settings.

How it works

  1. Upload your HTML file via the file upload endpoint
  2. Create a job via POST /tools/convert/html-to-pdf with the file ID and optional page settings
  3. Poll the job via GET /tools/jobs/{jobId} until status is COMPLETED
  4. Download the result via GET /tools/files/{fileId}/download

Basic request

At minimum, just provide the file ID of your uploaded HTML file:
This will produce an A4 portrait PDF with default margins (20mm top/bottom, 15mm left/right).

Full request with all options

Properties


Margins

Control the page margins using the margin object. Each value accepts a number with a unit (mm, cm, in, or px).
When using headerTemplate or footerTemplate, make sure the corresponding margin (top or bottom) is large enough to display the header/footer content.

Headers & Footers

Add repeating headers and footers to every page of your PDF. Templates are standard HTML strings and support special placeholders for page numbers:
Header and footer templates must include their own inline styling (font-size, colors, etc.) — they do not inherit styles from your HTML document.

CSS media emulation

By default, the conversion uses print media emulation. This means CSS rules inside @media print will apply, and some CSS frameworks may behave differently than expected. Set emulatedMediaType to "screen" if you want the PDF to look exactly like it does in a browser — particularly useful when using CSS frameworks like Tailwind CSS or Bootstrap.

Page breaks

You can control page breaks directly in your HTML using standard CSS print properties:

CSS @page rule

If you want full control over the page size and margins from within your HTML, use the CSS @page rule and enable preferCssPageSize:
When preferCssPageSize is enabled, the format and landscape API options are ignored in favor of your CSS rules.

Tips

  • External resources: The HTML file can reference external CSS, fonts, and images via URLs. These will be loaded during conversion.
  • Background colors: Background colors and images are always printed. No need for -webkit-print-color-adjust.
  • Maximum file size: The HTML file must be under 50 MB.
  • Timeout: The conversion allows up to 60 seconds for the page to load. If your HTML loads external resources, make sure they are accessible and responsive.