How it works
- Upload your HTML file via the file upload endpoint
- Create a job via
POST /tools/convert/html-to-pdfwith the file ID and optional page settings - Poll the job via
GET /tools/jobs/{jobId}until status isCOMPLETED - Download the result via
GET /tools/files/{fileId}/download
Basic request
At minimum, just provide the file ID of your uploaded HTML file:Full request with all options
Properties
Margins
Control the page margins using themargin object. Each value accepts a number with a unit (mm, cm, in, or px).
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:Example: Page numbers in footer
Example: Custom header and footer
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 usesprint 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:
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.
