# PDF to Image (render pages) API

> Render PDF pages to PNG or JPEG with PDFium: choose pages, DPI or width, get thumbnails, previews and the page text. Upload or URL.

- Endpoint: `GET | POST https://apibox.io.vn/v1/pdf-render`
- Category: Files
- HTML docs: https://apibox.io.vn/docs/pdf-render/ (Vietnamese: https://apibox.io.vn/vi/docs/pdf-render/)
- Online tool: https://apibox.io.vn/tools/pdf-render/
- Authentication: `Authorization: Bearer <API key>` or `X-API-Key: <API key>` (free key: https://apibox.io.vn/dashboard/#signup)

Upload a PDF (multipart `file`, raw body with `Content-Type: application/pdf`, `file_base64`) or give its `url`, pick the `pages` (`1`, `1-3,5`, `last`, `all`) and the resolution (`dpi`, default 96, or an exact pixel `width`, or `scale`), and get each page as PNG or JPEG. The default JSON answer lists every page with its pixel and point size and the image as a data URI; `format=png` or `format=jpeg` returns the image of one `page` directly, handy for `<img src>` previews and chat bots.

Rendering uses PDFium, the PDF engine of Chrome (BSD / Apache-2.0, via @hyzyla/pdfium, MIT) compiled to WebAssembly and running in a separate APIBox Worker; standard PDF fonts are built in, form fields are drawn, encrypted files open with `password`. `text=true` also returns the text of each page. `transparent=true` keeps the page background transparent (PNG).

Limits: PDF up to 20 MB (5 MB on the free plan), 20 pages per request (5 on Free), 12 megapixels per page and 30 MP per request: lower `dpi` or `width` for big pages.

## Parameters

| Name | In | Type | Required | Default | Description |
|---|---|---|---|---|---|
| `file` | body | file | no |  | The PDF (multipart, raw body with Content-Type application/pdf, or `file_base64`). |
| `url` | body|query | string | no |  | Public URL of the PDF instead of an upload. |
| `pages` | body|query | string | no | `1` | Pages for JSON output: `1`, `1-3,5`, `2-`, `last`, `all`. |
| `page` | body|query | number | no | `1` | The page returned with `format=png\|jpeg`. |
| `dpi` | body|query | number | no | `96` | Resolution, 18-600. |
| `width` | body|query | number | no |  | Exact image width in pixels (overrides dpi). |
| `format` | body|query | string | no | `json` | `json`, `png` or `jpeg` (binary image of one page). |
| `image_format` | body|query | string | no | `png` | Image type inside the JSON: `png` or `jpeg`; `quality` 10-100 for JPEG. |
| `text` | body|query | boolean | no | `false` | Also return the text of each page. |
| `password` | body | string | no |  | Password of an encrypted PDF. |

## Example request

```bash
curl -X POST "https://apibox.io.vn/v1/pdf-render" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -F "file=@./my-file"
```

## Example response

```json
{
  "source": "upload",
  "page_count": 3,
  "image_format": "png",
  "scale": 1,
  "pages": [
    {
      "page": 1,
      "width": 595,
      "height": 842,
      "width_pt": 595,
      "height_pt": 842,
      "bytes": 8794,
      "text": "Trang 1 - Hoá đơn giá trị gia tăng",
      "image": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAlMAAANKCAIAAA…"
    }
  ]
}
```

## Use cases

- Show a thumbnail of uploaded invoices or contracts in your app
- Send a page preview of a PDF to Zalo / Telegram bots
- Make Open Graph images of PDF documents
- Turn exam papers or catalogues into images for a web viewer

## FAQ

### What resolution should I use?

dpi=96 for screens, 150 for crisp previews, 300 for print. Or set width (pixels) to get a fixed-width thumbnail.

### Can it render scanned PDFs?

Yes, scanned pages are images inside the PDF and render like any page. Use ocr on the result if you need the text.

### Is WebP available?

Not yet: PNG (lossless) and JPEG (quality 10-100) are returned.
