Docs / Render a document

Rendering

Render a document

POST /v1/render creates one document. Give it a source and it returns a PDF or an image.

curl https://devilpdf.com/v1/render \
  -H "Authorization: Bearer $DEVILPDF_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "template": "invoice",
    "data": { "number": "INV-1001", "items": [{ "name": "Consulting", "quantity": 3, "unit_price": 150 }] },
    "filename": "invoice-1001"
  }'

#Source

Pass exactly one of these. Sending none, or more than one, returns invalid_request.

FieldTypeWhat it renders
templatestringA saved template, by id. Your own (tpl_...) or a starter: invoice, quote, certificate. See templates.
htmlstringHTML you send in the request. Add css for a stylesheet. See HTML to PDF.
urlstringA public web page. See URL to PDF.

#Body parameters

FieldTypeDefaultDescription
dataobject{}The JSON merged into the template. With html, sending data turns your HTML into an inline template.
cssstringExtra CSS. Used with html.
formatstring"pdf"pdf, png, jpeg or webp. jpg is accepted as jpeg. See images.
outputstring"url"url returns JSON with a download link. file returns the raw bytes. base64 returns JSON with the file in a base64 field.
optionsobjectPage setup and capture options. See below.
pdfobjectPassword, metadata and form fields. PDF only. See below.
filenamestringtemplate nameName of the file, without extension. The right extension is added for you.
expires_innumberplan maximumSeconds the download link stays valid. Minimum 60. The maximum depends on your plan.
destinationstringSet to "s3" to deliver the file to your own bucket. Paid plans.
metadataobjectUp to 20 of your own key/value pairs, returned on the document and in webhooks. Keys up to 60 characters, values up to 500.
asyncbooleanfalseReturn immediately and render in the background. See async and batch.
webhook_urlstringAn https URL to notify when this document succeeds or fails, in addition to your webhook endpoints.

#Options

options controls the page and how it is captured. Every field is optional. For a template, anything you set here overrides the template's own settings for this one render.

#Page setup

OptionTypeDefaultDescription
page_sizestring"A4"A3, A4, A5, Letter, Legal or Tabloid.
orientationstring"portrait"portrait or landscape.
marginstring"15mm 16mm 17mm"One to four CSS lengths, like the CSS margin shorthand. Units: mm, cm, in, pt, px.
fontstring"inter"Body font: inter, source-serif, jetbrains-mono or system. Templates and kit documents only.
heading_fontstringsame as fontFont for headings. Same choices.
accentstring"#111827"Accent colour as hex. Templates and kit documents only.
page_numbersbooleanfalsePrint "1 / 3" in the bottom right of every page.
header_textstringShort text at the top left of every page. Up to 200 characters.
footer_textstringShort text at the bottom left of every page. Up to 200 characters.

#Capture

OptionTypeApplies toDescription
kitbooleanhtmlInclude the print kit: fonts, table and layout classes. Off by default for raw HTML.
javascriptbooleanhtmlRun scripts in your HTML before capture. Off by default. Templates never run scripts. Pages loaded by url always do.
mediastringallCSS media type: print or screen. Defaults to print for PDFs from templates and HTML, screen for URLs and images.
wait_forstringallA CSS selector. Capture waits until an element matches.
delaynumberallExtra milliseconds to wait before capture. Maximum 10000.
scalenumberPDFZoom factor from 0.1 to 2.
page_rangesstringPDFPages to keep, for example "1-3, 5".

Image-only options (width, height, device_scale, full_page, quality, transparent, selector) are covered in images.

#PDF options

pdf only applies when format is pdf. Using it with an image format returns invalid_request.

FieldTypeDescription
passwordstringPassword needed to open the file. Encrypted with AES-256.
owner_passwordstringPassword needed to change permissions. If you leave it out, the open password is used.
permissionsobjectWhat a reader may do without the owner password. See below.
metadataobjectDocument properties: title, author, subject, keywords (string or array), creator.
formbooleanTurn field placeholders into fillable form fields. See forms and signatures.

Permissions take effect when you set a password.

PermissionDefault
printingallowed
copyingallowed
annotatingallowed
filling_formsallowed
modifyingnot allowed
{
  "template": "tpl_8sK2mQx7Lp0aVn3RtYc1",
  "data": { "employee": "Dana Whitfield" },
  "pdf": {
    "password": "open-sesame",
    "permissions": { "copying": false, "printing": false },
    "metadata": { "title": "Offer letter", "author": "Northwind Studio" }
  }
}

#Response

With the default "output": "url", you get a document object.

{
  "object": "document",
  "id": "doc_nWWGc4ehhC44vpOsHFGn",
  "status": "succeeded",
  "format": "pdf",
  "url": "https://devilpdf.com/f/doc_nWWGc4ehhC44vpOsHFGn/invoice-1001.pdf?exp=1773532800&sig=8fe4b5c6330ae0d9427ba7e78b54a66c",
  "filename": "invoice-1001.pdf",
  "pages": 1,
  "bytes": 29384,
  "duration_ms": 412,
  "template": "invoice",
  "source": "template",
  "batch": null,
  "metadata": null,
  "error": null,
  "expires_at": "2026-03-15T14:02:11.000Z",
  "created_at": "2026-03-14T14:02:10.588Z",
  "completed_at": "2026-03-14T14:02:11.000Z"
}
FieldDescription
idDocument id. Use it with GET /v1/documents/:id.
statusqueued, processing, succeeded or failed.
urlSigned download link. null when nothing is stored ("output": "file"), or once the link has expired. For S3 delivery, the object's URL in your bucket.
pagesPage count. null for images.
bytesFile size.
duration_msTime spent rendering and storing.
sourcetemplate, html, url, or tool for PDF tools.
errornull, or { "type", "message" } when the document failed.
expires_atWhen the download link stops working. null for S3 delivery.

#Output modes

outputResponseStored
urlJSON document with url.Yes, until expires_at.
base64JSON document with url and a base64 field.Yes, until expires_at.
fileThe file bytes, with the right Content-Type. The headers devilpdf-document-id and devilpdf-pages identify it.No.

#Timeouts

Templates and HTML have 30 seconds to render. URLs have 45. A render that runs out of time returns render_timeout and is not counted against your usage.

#Errors

A failed render never counts against your allowance. Common cases:

TypeStatusCause
invalid_request400A field is missing or has the wrong type. The message says which.
not_found404The template id does not exist on your account.
template_error422The template has a syntax error. line and col point at it.
render_error422The page could not be loaded or rendered.
quota_exceeded429You have used this month's documents.

See errors for the full list.