Printmint.

Convert HTML to PDF with an API call

Updated

Printing HTML to PDF yourself means running a headless browser: installing Chromium, keeping it patched, sizing a pool of them and cleaning up after pages that hang. Printmint runs that for you. You send HTML, it prints it with Chromium the way Chrome's own Print to PDF does, and you get the PDF back.

1. Get an API key

Create a free account and make a key under API keys in the dashboard. The free plan includes 100 documents a month.

2. Send your HTML

curl -X POST https://api-printmint.plxi.us/v1/pdf/render \
  -H "X-API-Key: $PRINTMINT_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "html": "<h1>Order 1042</h1><p>Thanks for shopping with us.</p>",
    "css": "body { font-family: Inter, Arial, sans-serif; padding: 20mm; }",
    "pdf": { "page_size": "A4" },
    "inline": true
  }'

css is added to the document's head, so you can keep styles apart from the markup. Leave it out if your HTML has its own <style>.

3. Save the PDF

With "inline": true the PDF comes back in the response as base64:

{
  "pages": 1,
  "bytes": 18342,
  "content_type": "application/pdf",
  "pdf_base64": "JVBERi0xLjcK…",
  "credits": 1
}

Without it, you get a download link in file when the service stores files.

In Node:

const res = await fetch('https://api-printmint.plxi.us/v1/pdf/render', {
  method: 'POST',
  headers: { 'X-API-Key': process.env.PRINTMINT_KEY, 'Content-Type': 'application/json' },
  body: JSON.stringify({ html: '<h1>Order 1042</h1>', inline: true }),
});
const { pdf_base64 } = await res.json();
await fs.promises.writeFile('order-1042.pdf', Buffer.from(pdf_base64, 'base64'));

In Python:

import base64, os, requests

r = requests.post(
    "https://api-printmint.plxi.us/v1/pdf/render",
    headers={"X-API-Key": os.environ["PRINTMINT_KEY"]},
    json={"html": "<h1>Order 1042</h1>", "inline": True},
)
open("order-1042.pdf", "wb").write(base64.b64decode(r.json()["pdf_base64"]))

Page size, margins and breaks

The pdf object sets up the paper:

{
  "pdf": {
    "page_size": "Letter",
    "landscape": false,
    "margin": { "top": "18mm", "right": "16mm", "bottom": "20mm", "left": "16mm" }
  }
}

For a size that isn't a standard paper size, give width and height, such as "4in" and "6in" for a shipping label. Page breaks come from your CSS: break-before: page on an element starts it on a new page, and break-inside: avoid keeps a table row or a card in one piece.

Images and fonts

Images, stylesheets and web fonts load from public URLs, the same as in a browser. If your HTML uses relative paths, send base_url with the address they're relative to. For a document that must load nothing, send "offline": true and embed images as data: URLs.

Limits

One PDF can be up to 50 pages, from up to 2 MB of HTML, printed within 60 seconds. Each successful PDF costs one credit; a call that fails, such as one with HTML over the limit, isn't charged.

Next: add headers, footers and page numbers, or skip the HTML and print an invoice from JSON.