Skip to content
POST AI agent ready /v1/pdf/from-html

PDF from HTML API - Build Print-Ready HTML for PDF Export

Accepts an HTML string and optional format (A4 or letter) and landscape flag. Returns a complete HTML document with @page size rules and baseline print styles (margins, headings, paragraphs, blockquotes, code, images). Open the returned HTML in a browser or headless Chromium and use File > Print > Save as PDF to produce the actual PDF file.

Parameters

stringrequired

Page body HTML to wrap for printing.

object

Options object: format (A4 | letter, default A4), landscape (boolean, default false).

Code examples

curl -X POST https://api.botoi.com/v1/pdf/from-html \
  -H "Content-Type: application/json" \
  -d '{"html":"<h1>Invoice #1042</h1><p>Amount due: $249</p>","options":{"format":"letter","landscape":false}}'

When to use this API

Invoice and receipt generation

Render an invoice template from your data as HTML, wrap it for print with this endpoint, then rasterize via headless Chromium on your backend. The @page rules ensure margins and paper size are correct.

Report export from dashboards

Let users export a dashboard snapshot as PDF. Grab the rendered HTML, call this endpoint, and stream the wrapped document through Puppeteer to generate the final PDF.

Printable documentation

Convert docs pages to print-ready PDFs. The wrapper styles headings, code blocks, and images with sensible defaults so the output looks professional without custom CSS.

Frequently asked questions

Why doesn't this return a PDF directly?
Real PDF generation needs headless Chromium, Puppeteer, or wkhtmltopdf running as a native process. Cloudflare Workers don't run native processes without container bindings. This endpoint gives you the print-ready HTML; pair it with Chromium elsewhere in your stack.
What formats are supported?
A4 (210mm × 297mm) and letter (8.5in × 11in). Landscape orientation is available via options.landscape: true.
Are the baseline styles overridable?
Yes. Your HTML body can include <style> blocks that override the wrapper's defaults. The wrapper styles come first so your later rules win by source order.
What about custom fonts?
Default font is Georgia serif. For web fonts, include @font-face rules in your HTML body. Headless Chromium will fetch them during rendering.
How do I generate the PDF in Node.js?
Use Puppeteer: `const browser = await puppeteer.launch(); const page = await browser.newPage(); await page.setContent(wrappedHtml); const pdf = await page.pdf({format: "A4"});`

Get your API key

Free tier includes 5 requests per minute with no credit card required. Upgrade for higher limits.