Inkspan › Guides › How to convert a PDF to images in Node.js

How to convert a PDF to images in Node.js

Rasterising a PDF turns a document into something you can show in a browser, feed to a vision model, or use as a thumbnail. The /v1/pdf/to-images endpoint renders every page to PNG at a resolution you choose and returns the set as a ZIP archive.

The dpi parameter is the main lever: 72–96 for web previews, 150 (the default) for general display, and 300 when the images feed OCR or a vision model that benefits from detail.

Also in: cURL · Python

Node.js example

import fs from 'node:fs';

const fd = new FormData();
fd.append('file', new Blob([fs.readFileSync('input.pdf')]), 'input.pdf');
fd.append('dpi', "150");

const res = await fetch('https://api.inkspan.dev/v1/pdf/to-images', {
  method: 'POST',
  headers: { 'X-API-Key': process.env.INKSPAN_KEY },
  body: fd,
});
if (!res.ok) throw new Error(await res.text());
fs.writeFileSync('images.zip', Buffer.from(await res.arrayBuffer()));

Request parameters

NameTypeRequiredDescription
filefileyesThe PDF to rasterise.
dpiintegernoOutput resolution in dots per inch. Defaults to 150.

Response

Returns a ZIP archive as a binary stream with Content-Type: application/zip and Content-Disposition: attachment; filename=images.zip. Write the response body straight to disk — do not parse it as JSON.

Things that catch people out

Errors

StatusMeaningFix
401Invalid or missing API keySend your key in the X-API-Key header.
402Monthly quota exceededThe response reports used/quota. Upgrade at inkspan.dev/#pricing.
422Missing or invalid parameterCheck required fields in the table above — the body names the offending field.

Failed requests do not count against your quota; only successful ones are metered.

Frequently asked questions

What DPI should I use for a vision model?

300 is the usual choice when detail matters for OCR or extraction. For thumbnails and previews, 72–96 is plenty and far cheaper.

Can I render only one page?

Not directly. Split the PDF first and rasterise the page you need.

Can I get JPEG instead?

The endpoint returns PNG. Convert after download if you need a lossy format.

Get a free API key →

Related Manipulate guides: merge PDF files · split a PDF into pages · compress a PDF · add a watermark to a PDF · fill a PDF form