Endpoints
Every route takes a POST with multipart/form-data and answers with the file. Files
go in form parts named files; options are plain form fields. The base URL is
https://api.pdfdispatch.com. The older paths under /v1/forms/... keep working, so
code written for them does not have to change.
Routes
Convert to PDF
| What | Route |
|---|---|
| An HTML file, with its CSS, images and fonts | /v1/convert/html |
| A web page by its URL | /v1/convert/url |
| Markdown files | /v1/convert/markdown |
Office files (.docx, .xlsx, .pptx, .odt, ...) | /v1/convert/office |
Screenshots
The same as the HTML, URL and Markdown routes above, with screenshot in place of convert: /v1/screenshot/html, /v1/screenshot/url and /v1/screenshot/markdown. They answer with a PNG, JPEG or WebP image (form field format).
Edit PDFs
| What | Route |
|---|---|
| Merge PDFs | /v1/pdf/merge |
| Split PDFs | /v1/pdf/split |
| Convert to PDF/A or PDF/UA | /v1/pdf/pdfa |
| Read or write metadata | /v1/pdf/metadata/read, .../metadata/write |
| Read or write bookmarks | /v1/pdf/bookmarks/read, .../bookmarks/write |
| Embed file attachments | /v1/pdf/attachments |
| Factur-X / ZUGFeRD e-invoices | /v1/pdf/factur-x |
| Flatten form fields and annotations | /v1/pdf/flatten |
| Make PDFs smaller | /v1/pdf/optimize |
| Watermark or stamp | /v1/pdf/watermark, .../stamp |
| Rotate pages | /v1/pdf/rotate |
| Encrypt with a password | /v1/pdf/encrypt |
Each successful request to any of these routes counts as one PDF (what counts).
Headers
| Header | Direction | What it does |
|---|---|---|
Authorization | request | Your key (keys and authentication). |
Output-Filename | request | The name of the file in the answer, without the extension. Without it, the name is random. |
X-Request-Id | answer | The id of the request. Quote it when you write to support. |
Webhook-* | request | Send the result to your server instead (webhooks). |
HTML to PDF
Send one file named index.html. Other files of the same request (CSS, images, fonts) can be linked from it by their file name, for example <link rel="stylesheet" href="style.css">.
curl https://api.pdfdispatch.com/v1/convert/html \
--header "Authorization: Bearer $PDD_KEY" \
--header "Output-Filename: invoice-1042" \
--form files=@index.html \
--form files=@style.css \
--form files=@logo.png \
--form paperWidth=8.27 \
--form paperHeight=11.7 \
--form printBackground=true \
--output invoice-1042.pdf
A page header and footer: add files named header.html and footer.html; they are repeated on every page.
URL to PDF
Chromium opens the page as a browser would, JavaScript included. The page must be on the public internet.
curl https://api.pdfdispatch.com/v1/convert/url \
--header "Authorization: Bearer $PDD_KEY" \
--form url=https://example.com/report \
--form waitForSelector="#chart-ready" \
--output report.pdf
Markdown to PDF
Send an index.html that names the Markdown files with {{ toHTML "file.md" }}, and the Markdown files.
curl https://api.pdfdispatch.com/v1/convert/markdown \
--header "Authorization: Bearer $PDD_KEY" \
--form files=@index.html \
--form files=@notes.md \
--output notes.pdf
Office files to PDF
Word, Excel, PowerPoint, OpenDocument, RTF, plain text and many more. Several files in one request come back as a ZIP of PDFs, or as one PDF with merge=true.
curl https://api.pdfdispatch.com/v1/convert/office \
--header "Authorization: Bearer $PDD_KEY" \
--form files=@contract.docx \
--output contract.pdf
Fonts that are not in the document may be replaced by similar ones, which can move line breaks. Embed the fonts in the document to keep the exact look.
Merge PDFs
The files are merged in the order of their names (numbers first, then letters).
curl https://api.pdfdispatch.com/v1/pdf/merge \
--header "Authorization: Bearer $PDD_KEY" \
--form files=@1-cover.pdf \
--form files=@2-report.pdf \
--form files=@3-appendix.pdf \
--output merged.pdf
Common options
Form fields, sent with the files. A wrong value gets 400 with a plain-text message that names the field.
| Field | Routes | What it does |
|---|---|---|
paperWidth, paperHeight | HTML, URL, Markdown | Paper size in inches (default 8.5 × 11, US Letter; A4 is 8.27 × 11.7). Units like 210mm also work. |
marginTop, marginBottom, marginLeft, marginRight | HTML, URL, Markdown | Margins, in the same units. |
preferCssPageSize | HTML, URL, Markdown | Use the size from the page's CSS @page rule. |
printBackground | HTML, URL, Markdown | Print background colours and images. |
landscape | HTML, URL, Markdown, Office | Landscape pages. |
scale | HTML, URL, Markdown | Zoom the page (default 1.0). |
nativePageRanges | HTML, URL, Markdown, Office | Only some pages, for example 1-5, 8. |
waitDelay, waitForExpression, waitForSelector | HTML, URL, Markdown | Wait before printing: a time (2s), a JavaScript expression that becomes true, or a CSS selector that appears. |
emulatedMediaType | HTML, URL, Markdown | print (default) or screen CSS. |
merge | Office | Several files into one PDF. |
pdfa, pdfua | all converting routes | Make PDF/A (PDF/A-1b, PDF/A-2b, PDF/A-3b) or PDF/UA. |
metadata | all converting routes | JSON, for example {"Author":"Acme","Title":"Invoice 1042"}. |
userPassword, ownerPassword | all converting routes, encrypt | Encrypt the PDF with a password. |
Webhooks
For big files, have the result sent to your server instead of waiting for it. With the headers below the API
answers 204 No Content at once, makes the PDF, and then sends it to Webhook-Url.
| Header | What it does |
|---|---|
Webhook-Url | Where the file goes (required). |
Webhook-Events-Url | Where a JSON event goes after each webhook call, errors included. This, or Webhook-Error-Url, is required. |
Webhook-Error-Url | Where a JSON error goes if the conversion fails. Older; use Webhook-Events-Url. |
Webhook-Method, Webhook-Error-Method | The HTTP method of those calls: POST (default), PUT or PATCH. |
Webhook-Extra-Http-Headers | A JSON object of headers to add to the calls, for example your own token. |
curl https://api.pdfdispatch.com/v1/convert/url \
--header "Authorization: Bearer $PDD_KEY" \
--header "Webhook-Url: https://example.com/hooks/pdf" \
--header "Webhook-Events-Url: https://example.com/hooks/pdf-events" \
--header 'Webhook-Extra-Http-Headers: {"Authorization": "Bearer your-own-token"}' \
--form url=https://example.com/report
A webhook request counts as one PDF when it is accepted with 204. The calls to your server carry the request's X-Request-Id.
Pages and files the API fetches
The API fetches web pages for the URL routes, the images, styles and scripts your HTML links to, and calls your
webhooks. It reaches only the public internet: localhost, private networks and cloud metadata
addresses are refused. A refused URL gets 403; a refused image or style inside a page is left
out and the PDF is still made. Send local assets as files of the request instead.