HTML to PDF API

HTML to PDF API

POST the HTML your application generates, such as an invoice or a report, and get back a PDF printed by a headless Chromium browser. CSS, web fonts and JavaScript work as in a browser, and every PDF option of the API applies: paper size, margins, page ranges, print or screen styles.

Example request and response

Send the HTML and the options as JSON to POST /v1/take. The answer is the PDF itself; errors come back as JSON with a status code. The Render HTML documentation has examples in JavaScript, Python and PHP.

curl https://api.screenshotbase.com/v1/take \
  -H "apikey: YOUR-API-KEY" \
  -H "Content-Type: application/json" \
  -d '{"html": "<h1>Invoice INV-42</h1><p>Total: EUR 49.00</p>", "format": "pdf", "pdf_margin": "15mm"}' \
  -o invoice.pdf
HTTP/1.1 200 OK
Content-Type: application/pdf
X-Cost: 1

(the PDF, served as a download)

The request body

html
The HTML to render, at most 5 MB (5,242,880 bytes). A whole document or a fragment. It is accepted in the JSON body only, never in the query string.
format
pdf for a PDF. The same HTML can also become a PNG, JPG, WebP or GIF screenshot.
pdf_paper_format, pdf_landscape, pdf_margin, pdf_media_type, pdf_scale, pdf_page_ranges, pdf_fit_one_page
The PDF options, as for web pages: A4, Letter, Legal or A3, margins in mm, cm, in or px, at most 30 pages, or one long page.
wait_until, delay, hide_selectors, styles
Wait for scripts or late content (delay at most 7 seconds), hide elements, add CSS.
attachment_name, upload
Name the download, or store the PDF and get JSON with its URL instead. Anyone with that URL can open a stored file.
url
The same endpoint also renders a URL. Send either url or html, not both.

Use cases

Invoices and receipts

Render the invoice template your application already has, with your fonts and logo, as an A4 or Letter PDF.

Reports and statements

JavaScript runs before the page is printed, so charts drawn by script can be included; use wait_until or a short delay for late ones.

Certificates, tickets and labels

Design them in HTML and CSS, choose the paper size and margins, and print one PDF per recipient.

Quotes and contracts

Generate a PDF from the same HTML your customers see in the browser, with the page's print stylesheet.

AI agents

Through the MCP server, an agent sends HTML with the takePost tool. It passes upload: true and gets the URL of the stored file.

Start on the free plan

Rendering HTML is part of every plan, including the free plan with 300 requests a month. Each successful render counts as one request, whatever the format and also with upload=true; failed renders are not counted. Paid plans start at $15 a month for 3,000 requests.

Frequently asked questions

Do relative URLs in my HTML work?

No. The HTML is rendered as an https page on an address of its own, so relative URLs do not resolve. Use absolute URLs, embed small files as data: URLs, or add a base element to the head of the document. Plain http:// images are upgraded to https; other http:// resources, such as stylesheets or fonts, are blocked as mixed content.

Do you keep my HTML?

No. The HTML is written to a temporary file for the render and deleted afterwards. The PDF is stored only when you pass upload=true, and a stored file can be opened by anyone with its URL. For documents with personal data, such as invoices, take the PDF from the response instead.

Can the HTML load files from my internal network?

No. Everything the HTML references is held to the same rules as a web page: resources on private, loopback or other reserved addresses and internal host names are never fetched.

How long may a render take?

About 12 seconds from the start of the request: loading what the HTML references, the delay and printing. A slower render is stopped and answered with 408, which is not billed.

Does JavaScript in my HTML run?

Yes, as in a browser, so pages that build their content or charts with script work. Use wait_until or a short delay if content appears late.

Can I test without using my quota?

Yes. A sandbox API key returns a placeholder PDF without rendering the HTML and costs nothing (X-Cost: 0).

Related

More free tools

Start using our Screenshot API for free today!

Get 300 requests / month for free