API documentation

One endpoint: send a URL or HTML, get a PDF back. Get a free API key to start.

Quick start

POSThttps://pdfly.host/v1/convert

Send parameters as a form, JSON, or query string. Authenticate with your key in the header Authorization: Bearer YOUR_API_KEY. On success you get 200 with Content-Type: application/pdf.

curl -H "Authorization: Bearer YOUR_API_KEY" \
     -d url=https://example.com \
     -d page_size=A4 \
     -o example.pdf \
     https://pdfly.host/v1/convert

Authentication

Any of these work: Authorization: Bearer KEY, X-Api-Key: KEY, HTTP Basic with the key as username or password, or a key parameter. Keep keys on your server — never put them in front-end JavaScript.

Check your usage

curl -H "Authorization: Bearer YOUR_API_KEY" https://pdfly.host/v1/account

Parameters

NameTypeDefaultDescription
urlstring—Web page to convert. Send either url or text.
textstring—HTML to convert (max 10 MB). Assets must use absolute URLs. html also works.
page_sizestringA4A0–A6, Letter, Legal, Tabloid, Ledger.
page_width / page_heightlength—Custom page size, e.g. 80mm. Overrides page_size.
orientationstringportraitportrait or landscape.
margin_top / _right / _bottom / _leftlength0.4inUnits: mm, cm, in, pt, px, pc. margin sets all four.
no_marginsboolfalseZero margins.
header_html / footer_htmlstring—HTML on every page. Placeholders: <span class="pageNumber">, totalPages, title, url, date. Margin grows to 20mm automatically.
use_print_mediaboolfalseUse the page's @media print CSS instead of screen CSS.
no_backgroundboolfalseDon't print background colors and images.
javascript_delayint (ms)0Wait after page load before printing (max 30000). For JS-heavy pages.
wait_for_elementstring—CSS selector: wait until it exists, e.g. #chart-ready.
scale_factorint (%)100Zoom, 10–200.
print_page_rangestringalle.g. 1-3,5.
single_pageboolfalseWhole page as one long PDF page.
css_page_sizeboolfalseLet CSS @page { size: … } decide the page size.
filenamestringdocument.pdfName in the Content-Disposition header.
attachmentboolfalseMake browsers download instead of display.

Booleans accept true/false, 1/0.

Errors

Errors come back as JSON: {"error": {"status": 400, "message": "…"}}

400Bad parameters — the message says which one.
401Missing or invalid API key.
402Monthly quota used up.
403Key disabled.
422The page couldn't be rendered (e.g. it returned a 5xx error).
429Too many requests per minute — retry after the Retry-After seconds.
502–504Renderer problem or timeout — safe to retry.

Moving from pdfcrowd

Parameter names and PHP client methods match pdfcrowd's, so most integrations only need the class name and credentials changed:

- $client = new \Pdfcrowd\HtmlToPdfClient('username', 'apikey');
+ $client = new \Pdfly\HtmlToPdfClient('YOUR_API_KEY');

- catch (\Pdfcrowd\Error $why)
+ catch (\Pdfly\Error $why)

Header/footer placeholders pdfcrowd-page-number and pdfcrowd-page-count are translated automatically.