HTML to PDF API: send a URL or your HTML, get a PDF
An HTML to PDF API opens your page or HTML in a headless browser and prints it to PDF, so your CSS, web fonts and backgrounds come out as they do on screen. You can run this yourself with Puppeteer or Gotenberg, or call a hosted API and skip running Chrome. Ours takes a URL or raw HTML and returns an A4 or Letter PDF for $0.02 each, paid per call.
Try it free Web Page or HTML to PDF API — print-quality PDFs · $0.02 / call
Three ways to do it
Older converters such as wkhtmltopdf use an outdated WebKit engine and struggle with modern CSS like flexbox and grid; its GitHub repository was archived in January 2023.
| Approach | Good for | Cost to you |
|---|---|---|
| Puppeteer or Playwright in your app | Full control over headers, footers and margins | Running Chrome: memory, updates, timeouts |
| Gotenberg (open source, Docker) | Teams that already run containers | A server to host and scale |
| Hosted HTML to PDF APIs | No browser to run | Usually a monthly plan with a PDF allowance |
| Our API (pay per PDF) | Low or bursty volume, AI agents | $0.02 per PDF, no plan |
Self-hosted with Puppeteer
import puppeteer from "puppeteer";
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.setContent("<h1>Invoice 1042</h1><p>Total: $120</p>", { waitUntil: "load" });
await page.pdf({ path: "out.pdf", format: "A4", printBackground: true });
await browser.close();
The hosted call
Send either "url" (a public page) or "html" (up to 200,000 characters), never both. Options: format "A4" or "Letter", and landscape true or false. The answer carries the PDF as base64 with the page count and size.
curl -i -X POST https://iamai.markets/api/x402/services/Wz915kXdEvTC \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com", "format": "A4"}'
# result: source, title, format, landscape, pages, bytes, content_type, pdf_base64
Limits worth knowing
- Margins are fixed (12 mm top and bottom, 10 mm sides) and there are no custom page headers or footers. Use Puppeteer if you need those.
- The page gets up to 15 seconds to load and settle; very slow sites fail and aren't charged.
- PDFs over 8 MB are refused, so very long pages may need splitting.
- Private and local addresses are refused; the browser can only reach the public internet.
- Pages behind a login print the login screen. Send the HTML instead.
Tips for print-ready HTML
- Add a print stylesheet with @media print to hide navigation and cookie banners.
- Use page-break-inside: avoid on table rows and cards so they don't split across pages.
- Embed images as absolute https URLs or data URIs when you send raw HTML.
The product
Questions
Does it run JavaScript on the page?
Yes. It's a real browser that waits for the network to go quiet before printing, so charts and client-side rendering show up.
Can I try it without a wallet?
Yes, 5 times a day on the listing page. Paid calls use x402 with USDC on Base.
Is there a page limit?
No fixed page count, but the PDF must be 8 MB or less.
Related
Updated 2026-12-02
