# PNG output (/docs/guides/png-output)

> Render one page of a document as a PNG image for previews, thumbnails and images in emails or messages.

Besides PDFs, Druckling can render one page of a document as a PNG image. Use it where a PDF is awkward: a preview in your app, a thumbnail in a list, a ticket or certificate shown inline in an email or a chat message.

A PNG render takes the same template, data and language as a PDF render. You add `format: "png"` and, optionally, which page to render and at what resolution.

## Render a page as PNG [#render-a-page-as-png]

Send `format: "png"` to [`POST /v1/documents`](/docs/api-reference/documents/create). The `image` object picks the page and the scale:

```bash tab="cURL"
curl https://druckling-nine.vercel.app/v1/documents \
  -H "Authorization: Bearer $DRUCKLING_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "template": "invoice-standard",
    "format": "png",
    "image": { "page": 1, "scale": 1 },
    "filename": "INV-2041-preview",
    "data": {
      "invoice": { "number": "INV-2041", "due_date": "2026-11-22" },
      "customer": { "name": "Northwind Ltd.", "address": "12 Pier St, Leeds" },
      "line_items": [
        { "description": "Design system audit", "qty": 12, "rate": 180, "amount": 2160 }
      ],
      "totals": { "subtotal": 2160, "tax": 172.8, "amount": 2332.8 }
    }
  }'
```

```ts tab="TypeScript"
import Druckling from "@druckling/sdk";

const druckling = new Druckling(); // reads DRUCKLING_API_KEY

const document = await druckling.documents.create({
  template: "invoice-standard",
  format: "png",
  filename: "INV-2041-preview",
  data: {
    invoice: { number: "INV-2041", due_date: "2026-11-22" },
    customer: { name: "Northwind Ltd.", address: "12 Pier St, Leeds" },
    line_items: [{ description: "Design system audit", qty: 12, rate: 180, amount: 2160 }],
    totals: { subtotal: 2160, tax: 172.8, amount: 2332.8 },
  },
});

const png = await druckling.documents.download(document); // Uint8Array
```

```python tab="Python"
from druckling import Druckling

client = Druckling()  # reads DRUCKLING_API_KEY

document = client.documents.create(
    template="invoice-standard",
    format="png",
    filename="INV-2041-preview",
    data={
        "invoice": {"number": "INV-2041", "due_date": "2026-11-22"},
        "customer": {"name": "Northwind Ltd.", "address": "12 Pier St, Leeds"},
        "line_items": [{"description": "Design system audit", "qty": 12, "rate": 180, "amount": 2160}],
        "totals": {"subtotal": 2160, "tax": 172.8, "amount": 2332.8},
    },
)

client.documents.download_to(document, "INV-2041-preview.png")
```

```php tab="PHP"
<?php

require __DIR__ . '/vendor/autoload.php';

use Druckling\Druckling;

$druckling = new Druckling(); // reads DRUCKLING_API_KEY

$document = $druckling->documents->create(
    template: 'invoice-standard',
    format: 'png',
    filename: 'INV-2041-preview',
    data: [
        'invoice' => ['number' => 'INV-2041', 'due_date' => '2026-11-22'],
        'customer' => ['name' => 'Northwind Ltd.', 'address' => '12 Pier St, Leeds'],
        'line_items' => [['description' => 'Design system audit', 'qty' => 12, 'rate' => 180, 'amount' => 2160]],
        'totals' => ['subtotal' => 2160, 'tax' => 172.8, 'amount' => 2332.8],
    ],
);

$druckling->documents->downloadTo($document, __DIR__ . '/INV-2041-preview.png');
```

<Callout type="info" title="The SDKs render page 1 at the default scale">

The SDKs send `format`, but not the `image` options yet. Their PNGs are page 1 at scale 2. For another page or scale, call the REST API directly, as in the cURL example.

</Callout>

## Options [#options]

<TypeTable
  type={{
    format: { type: '"pdf" | "png" | "xml"', description: 'Set to "png" to render an image. Defaults to what the template produces.' },
    "image.page": { type: "integer", description: "The page to render, starting at 1.", default: "1" },
    "image.scale": { type: "number", description: "Pixels per point, from 0.5 to 4. 1 is 72 dpi, 2 is 144 dpi, 4 is 288 dpi.", default: "2" },
  }}
/>

`image` is only allowed together with `format: "png"`. The other parameters (`template`, `version`, `data`, `filename`, `async`, `language`) work exactly as for PDFs.

### Pixel size [#pixel-size]

A point is 1/72 inch, so the resolution is 72 × `scale` dpi, and the image is the page size in points × `scale`, rounded to whole pixels:

| Page | `scale: 0.5` | `scale: 1` | `scale: 2` (default) | `scale: 4` |
| --- | --- | --- | --- | --- |
| A4 portrait | 298 × 421 | 595 × 842 | 1191 × 1684 | 2381 × 3368 |
| A4 landscape | 421 × 298 | 842 × 595 | 1684 × 1191 | 3368 × 2381 |
| A5 portrait | 210 × 298 | 420 × 595 | 839 × 1191 | 1678 × 2381 |
| A6 landscape | 210 × 149 | 420 × 298 | 839 × 595 | 1678 × 1191 |
| Letter portrait | 306 × 396 | 612 × 792 | 1224 × 1584 | 2448 × 3168 |

The image always has the page's proportions, and page sizes are paper and label formats. For a fixed image format such as a 1200 × 630 social card, crop or resize the PNG yourself.

The page is drawn on a white background: transparent areas come out white, as in a PDF viewer.

## The response [#the-response]

A PNG render returns a [document](/docs/concepts/documents) like a PDF render does, with a few differences:

```json
{
  "id": "pdf_8Qw2kLm3nP0aB1cD",
  "object": "document",
  "status": "rendered",
  "template": "invoice-standard",
  "version": 1,
  "filename": "INV-2041-preview.png",
  "format": "png",
  "content_type": "image/png",
  "image": { "page": 1, "scale": 1, "width": 595, "height": 842 },
  "pages": 1,
  "size_bytes": 61204,
  "url": "https://…",
  "expires_at": "2026-11-21T10:02:11.000Z",
  "error": null,
  "einvoice": null,
  "batch": null,
  "language": "en",
  "test_mode": true,
  "created_at": "2026-10-22T10:02:10.000Z"
}
```

- `format` is `png` and `content_type` is `image/png`.
- `image` repeats the page and scale and adds the `width` and `height` in pixels once the image is rendered. For an `async: true` request they're `null` until the document is `rendered`.
- `pages` is always 1: the file holds one page, however long the document is.
- The file name ends in `.png`. If you pass a `filename` ending in `.pdf`, the extension is replaced.

Download the image from `url` like any other document. The signed URL works without an API key, so a browser can also load it directly until it expires; see [Documents](/docs/concepts/documents) for how long URLs and files last. For images in emails, download the PNG and attach or host it yourself, so it keeps working after the URL expires.

## Which templates render PNG [#which-templates-render-png]

Any template without e-invoicing can render PNG. E-invoice templates can't:

- Factur-X and ZUGFeRD templates render `pdf` only, because the invoice XML has to be embedded in a PDF/A-3.
- XRechnung and Peppol BIS templates render `xml` only.

Asking them for a PNG answers 422 `validation_failed` on `format`. See [E-invoicing](/docs/guides/e-invoicing).

A template's PDF standard (PDF/A or PDF/UA) doesn't apply to images: the PNG is rendered from the same layout without a conformance claim, and the document's timeline in the dashboard notes it. See [Accessible PDFs](/docs/guides/accessible-pdfs).

To render page 3, Druckling typesets the whole document and then draws that page, so a PNG takes about as long as the PDF and the same page limit applies.

## Errors [#errors]

| Problem | Response |
| --- | --- |
| `image` without `format: "png"` | 422 `validation_failed`, `field: "image"`: `` `image` options only apply to format "png" `` |
| `image.page` past the end of the document | 422 `validation_failed`, `field: "image.page"`: `Page 3 does not exist: the document has 1 page`. `data.pages` holds the page count |
| `image.page` below 1 or not a whole number, `image.scale` outside 0.5 to 4 | 400 `BAD_REQUEST`, `Input validation failed`, with the offending path in `data.issues` |
| An e-invoice template | 422 `validation_failed`, `field: "format"` |

The page count is only known after typesetting, so `image.page` past the end is reported by the render. With `async: true` the request is accepted, and the document ends `failed` with that error (and a `document.failed` [webhook](/docs/guides/webhooks) if you subscribed). If you don't know how long a document will be, render page 1, or render the PDF first and read its `pages`.

## Usage and batches [#usage-and-batches]

- In live mode, each rendered PNG counts as one document toward your [plan's quota](/docs/concepts/plans-and-limits), like a PDF. Failed renders don't count, and test-mode renders never do.
- [Batches](/docs/guides/batches) render PDFs (or XML for XRechnung and Peppol templates), not PNGs. To make images of many records, send one request per record, with `async: true` and [webhooks](/docs/guides/webhooks) for large volumes.
- [Share links](/docs/concepts/share-links) work for PNG documents too.

## Use cases [#use-cases]

- **Thumbnails.** Show `scale: 0.5` previews of generated invoices or contracts in your app's lists.
- **Previews before sending.** Let a user check page 1 as an image before you send the PDF.
- **Images in emails and messages.** Many email clients and chat apps show images inline but PDFs only as attachments. Render a ticket or a certificate as PNG at `scale: 2` for sharp text on high-density screens.
- **Every language.** Pass `language` to preview each [translation](/docs/guides/languages) of a template.
