PDF to PNG API
PNG keeps every pixel exactly as the page was drawn. On pages built from type, rules and flat color, such as contracts, spreadsheets, charts, floor plans and wiring diagrams, that means not a speck of blur around a letter or a line. It matters whenever software reads the image next, or someone enlarges, crops or compares it.
The PDF to PNG API is the PDF to Image API with format=png. You get each page as a lossless PNG inside JSON, next to the page's text, or a single page as raw .png bytes when you send Accept: image/png.
Each page counts as 10 API calls against your monthly quota. Requests that fail are not counted, and the X-Api-Calls-Charged response header shows how many API calls each request used. See pricing.
Where PNG Beats JPG
- Fine print. Footnotes, legal terms and the digits in table cells keep hard edges at any zoom level.
- Line art, charts and diagrams. Hairlines and solid fills stay solid, with no halo along the edges.
- Input for OCR and models. No compression noise for a text recognizer or a vision model to misread.
- More processing later. Crop, annotate, diff two revisions of a drawing, or re-encode for the web later, without losses piling up.
On text-heavy pages the lossless format costs little: about a fifth more than JPG at 72 and 150 DPI, and the same size at 300 DPI.
When Not to Use PNG
- Scans and photo pages. PNG comes out 5 to 6 times larger than JPG with nothing visible gained; the PDF to JPG API suits them better.
- Images for web pages. WebP (
format=webp) is roughly half the size of JPG and far smaller than PNG. - Many pages per call at 300 DPI. Big PNGs leave room for only a few pages in each response.
- Transparent backgrounds. Pages are always drawn on white, so PNG output has a white background like every other format.
PNG vs JPG vs WebP: Size per Page
| Page content | dpi | PNG | JPG | WebP | PNG vs JPG |
|---|---|---|---|---|---|
| Text (a contract) | 72 | 150 KB | 120 KB | 70 KB | 1.2x |
| 150 | 430 KB | 360 KB | 210 KB | 1.2x | |
| 300 | 920 KB | 920 KB | 460 KB | 1.0x | |
| Tables (a data dictionary) | 72 | 90 KB | 90 KB | 50 KB | 1.0x |
| 150 | 310 KB | 300 KB | 150 KB | 1.0x | |
| 300 | 740 KB | 840 KB | 350 KB | 0.9x | |
| Photos | 72 | 240 KB | 40 KB | 30 KB | 6x |
| 150 | 760 KB | 140 KB | 80 KB | 5x | |
| 300 | 2.6 MB | 450 KB | 240 KB | 6x |
Measured on three sample documents, rounded; JPG and WebP at their default quality of 85. At 300 DPI, PNG is no larger than JPG on text and tables.
Save One Page as a PNG File (Node.js)
Send Accept: image/png together with format=png and the response body is the PNG itself, for the first page in pages. This script posts the PDF as the raw request body and writes page 3 of a wiring diagram to disk:
// Node.js 18+, no packages needed: save page 3 of a PDF as a PNG file
const fs = require('fs');
async function savePageAsPng(pdfPath, pageNumber, pngPath) {
const response = await fetch(
`https://api.api-ninjas.com/v1/pdftoimage?format=png&dpi=200&pages=${pageNumber}`, {
method: 'POST',
headers: {
'X-Api-Key': 'YOUR_API_KEY',
'Content-Type': 'application/pdf', // the body is the PDF itself
'Accept': 'image/png', // reply with the PNG bytes, not JSON
},
body: fs.readFileSync(pdfPath),
});
if (!response.ok) throw new Error(`HTTP ${response.status}: ${await response.text()}`);
fs.writeFileSync(pngPath, Buffer.from(await response.arrayBuffer()));
}
savePageAsPng('wiring-diagram.pdf', 3, 'wiring-diagram-page-3.png').catch(console.error);next_page points at the following page. When a single page is too big by itself, the request fails with Page 1 is too large to return at 300 DPI as PNG. Use a lower dpi or format=jpg. Lower dpi, ask for fewer pages at a time with pages, or send photo pages as JPG.https://api.api-ninjas.com/v1/pdftoimage
Converts the pages of a PDF to lossless PNG images with format=png. Returns each page as a base64 image with its size and its text, or one page as a raw image file. Accepts GET or POST: use POST to upload the PDF, or GET with url.
Parameters
Send the PDF in one of three ways: as file (a multipart form upload), as url, or as the raw request body with Content-Type: application/pdf (up to about 4 MB). The other parameters can be query parameters or multipart form fields.
fileoptionalThe PDF, as a multipart form upload (
multipart/form-data), up to about 4 MB. Send one PDF per request.urloptionalA public
http://orhttps://link to the PDF, up to 25 MB, e.g.https://example.com/report.pdf. Works with GET or POST.pagesoptionalThe pages to convert: one page (
1), a range (2-5), a list (1,3,7-9) or a range to the end (4-, page 4 to the last page). Page 1 is the first page. Default: every page, up to 10 per request (see limits).formatset to pngpngfor PNG images. Without it the endpoint returns JPGs (jpg, the default);webpis also available. The live demo offers all three so you can compare sizes.dpioptionalResolution in dots per inch, from
30to300. Default150. At 150 DPI a US Letter page is about 1275 x 1650 pixels; at 300 DPI, 2550 x 3300.passwordoptionalThe password of a password-protected PDF.
Headers
X-Api-KeyrequiredAPI Key associated with your account.
Acceptoptionalimage/pngorimage/*returns the first requested page as a raw image file instead of JSON. Send it together withformat=png.Content-Typeoptionalapplication/pdfwhen the request body is the PDF itself. Multipart uploads set their own content type.
Response
The /v1/pdftoimage endpoint returns a JSON object with the following fields, or an error if the request is unsuccessful (see errors).
page_countNumber of pages in the PDF.
next_pageThe next requested page that is not in this response, because of the per-request limits, or
nullwhen every requested page was returned. To continue, send the same request withpagesstarting atnext_page, e.g.pages=11-.pagesThe converted pages, in the order requested, each with the fields below.
pages[].pagePage number in the PDF (1 is the first page).
pages[].formatjpg,pngorwebp.pages[].width, pages[].heightImage size in pixels.
pages[].textThe text on the page, as plain text. Empty for scanned pages, whose text is part of an image; to read those, send the page image to the Image to Text API.
pages[].imageThe image file, base64-encoded.
With an image Accept header, the response body is the raw image of the first requested page, with Content-Type image/png. Every successful response has an X-Api-Calls-Charged header with the number of API calls the request counted.
Limits
- Up to 10 pages per request.
- Each response carries up to about 4 MB of images. At high DPI fewer pages fit (around four text pages at 300 DPI); the rest are left for the next request, from
next_page. - Pages wider or taller than 5,000 pixels, or larger than 12 megapixels, at the requested DPI are scaled down to fit.
- Uploads up to about 4 MB; PDFs from
urlup to 25 MB.
API Calls
Each page returned counts as 10 API calls: a response with 3 pages counts as 30. Requests that fail are not counted. If your remaining quota covers fewer pages than you asked for, the response returns the pages it covers, and next_page points at the rest.
Live Demo
Get a free API key to get started — no credit card required.

The live demo converts one page at up to 150 DPI, from PDFs up to 2 MB. No API key is needed to try it.
Code Examples
# Convert pages of document.pdf; the JSON holds each page as a base64 image
curl -X POST "https://api.api-ninjas.com/v1/pdftoimage?pages=1-3&format=png&dpi=150" \
-H "X-Api-Key: YOUR_API_KEY" \
-F "file=@document.pdf"
# Or save page 1 as a PNG file
curl -X POST "https://api.api-ninjas.com/v1/pdftoimage?pages=1&format=png&dpi=150" \
-H "X-Api-Key: YOUR_API_KEY" \
-H "Accept: image/png" \
-F "file=@document.pdf" \
--output page-1.pngErrors
An invalid request returns HTTP 400 with a JSON body holding a readable error message, and is not counted against your quota. Authentication and quota errors use the standard format described in error codes.
| Cause | Example error |
|---|---|
| No PDF in the request | Send a PDF as file (a multipart form upload) or as url (a link to the PDF). |
| The file is not a PDF | The file is not a PDF. |
A password-protected PDF without password | This PDF is password-protected. Send its password in the password parameter. |
A wrong password | The password is incorrect for this PDF. |
pages outside the PDF, e.g. pages=5 for a 3-page PDF | pages is outside this PDF, which has 3 pages. |
A pages value that is not a page list | pages must be page numbers or ranges such as 1, 2-5, 1,3,7-9 or 4- (page 4 to the end). |
A format other than jpg, png or webp | format must be jpg, png or webp. |
A number out of range, e.g. dpi=600 | dpi must be between 30 and 300. |
A PDF at url over 25 MB | The PDF at url is larger than 25 MB. |
| One page alone is too large for a response | Page 1 is too large to return at 300 DPI as PNG. Use a lower dpi or format=jpg. |
Frequently Asked Questions
Can I use the PDF to PNG API for commercial purposes?
Yes, but you must have a premium subscription. Commercial use of the PDF to PNG API is not permitted on the free tier. See our pricing page to choose a plan that fits your needs.How do I get an API key and start using the PDF to PNG API?
Sign up for a free account to instantly get your API key, then pass it in theX-Api-Keyheader on every request. The documentation above includes ready-to-run examples in cURL, Python, JavaScript, Node.js, and more.What happens if I exceed my quota for the month?
Your API requests will simply be denied once you hit your monthly quota — you will never be charged more than the plan you signed up for. To increase your quota, you can upgrade your plan any time on our pricing page.What happens if a request to the PDF to PNG API fails?
The API responds with a standard HTTP status code and a JSON error message describing the problem. See our error codes reference for the full list of codes and how to resolve each one, or contact support if you need help.How do I convert a PDF to PNG with an API?
Send the PDF to/v1/pdftoimagewithformat=png: as a multipartfileupload, as the raw body withContent-Type: application/pdf, or as aurl. The JSON response holds each page as a base64 PNG with its size and text. WithAccept: image/pngas well, the response is the PNG of the first requested page as a file.Do the PNG images have a transparent background?
No. Every page is drawn on a white background, the way it looks in a PDF viewer or on paper, and PNG output has that white background too.Is PNG better than JPG for OCR?
Often, yes: PNG has no compression noise around letters for a recognizer to stumble on, and at 300 DPI a text page is about the same size in both formats (around 920 KB in our measurements). PDFs that contain real text, rather than scans, don't need OCR at all: each page'stextfield already holds it. For scanned pages, send the images to the Image to Text API.Why are my PNG files so much larger than JPGs?
Pages made of photos or scans compress poorly without loss: in our measurements a photo page was 5 to 6 times larger as PNG than as JPG, for example about 760 KB against 140 KB at 150 DPI. Text and table pages stay close to JPG size. For photo-heavy PDFs, use the PDF to JPG API orformat=webp.Does the quality parameter change PNG output?
No. PNG is lossless, soqualityonly applies tojpgandwebp. The size of a PNG depends ondpiand on what is on the page.
Explore API integration use cases for recommended APIs and workflow examples.