Docs / Images

Rendering

Images

Any source that renders to a PDF can render to an image. Set format to png, jpeg or webp.

curl https://devilpdf.com/v1/render \
  -H "Authorization: Bearer $DEVILPDF_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "template": "certificate", "format": "png", "data": { "recipient": { "name": "Amara Okonkwo" } } }'

Images count as one document each, the same as PDFs.

#Options

OptionTypeDefaultDescription
widthnumberpage width, or 1280 for URLsViewport width in CSS pixels. 16 to 4000.
heightnumberpage height, or 800 for URLsViewport height in CSS pixels. 16 to 8000.
device_scalenumber2 for templates, otherwise 1Pixel density, 1 to 3. At 2, a 794 pixel wide page becomes a 1588 pixel wide image.
full_pagebooleantrueCapture the whole scrollable page. Set false to capture only the viewport.
qualitynumber90Compression quality for jpeg and webp, 1 to 100. Ignored for png.
transparentbooleanfalseLeave the background transparent. png and webp only.
selectorstringCapture only the first element matching this CSS selector.

#Templates as images

A template rendered to an image keeps its page shape. The viewport is set to the template's page size (A4 portrait is 794 by 1123 CSS pixels), and the page margin becomes padding around the content. A document longer than one page becomes one tall image.

Images have no page margins to print into, so page_numbers, header_text and footer_text have no effect.

#Social cards and thumbnails

For a fixed-size image, send HTML with an explicit viewport and turn off full_page.

{
  "html": "<div class=\"card\"><h1>{{ title }}</h1><p>{{ author }}</p></div>",
  "css": "body { margin: 0 } .card { width: 1200px; height: 630px; padding: 80px; box-sizing: border-box; background: #09090a; color: #fff; font: 600 28px system-ui } h1 { font-size: 72px; margin: 0 0 24px }",
  "data": { "title": "Shipping PDFs without tears", "author": "Dana Whitfield" },
  "format": "png",
  "options": { "width": 1200, "height": 630, "full_page": false }
}

#Capture one element

selector crops the image to a single element, which is handy for charts and receipts.

{ "url": "https://example.com/pricing", "format": "webp", "options": { "selector": "#pricing-table", "quality": 85 } }

If nothing matches, the render fails with render_error.

#Media type

Images use screen styles by default. Set options.media to "print" to apply print styles.