PNG to PDF API
Screenshots for a bug report or a design review, architecture diagrams, a dashboard exported for the monthly review: software saves pictures of screens and drawings as PNG, and people hand them around as PDF, attached to tickets, filed with reports or printed for a meeting. The PNG to PDF API places PNGs on PDF pages, one image per page, in a single request.
Behind it is /v1/imagetopdf, the Image to PDF API endpoint, which accepts JPG, WebP, GIF, TIFF and BMP too.
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.
Lossless Storage
Unless you set quality, every PNG is stored in the PDF without loss: the same pixels, the same crisp lettering in a screenshot, the same one-pixel lines in a diagram. In our measurements three 2560 x 1800 screenshots, 1,374 KB as PNG files, made a PDF of 1,374 KB, so the container adds next to nothing.
When the PDF must be smaller, quality turns each PNG into a JPG page. quality=80 took those three screenshots down to 855 KB, with slightly softer edges around text. Charts and diagrams made of large flat areas often stay smaller as PNG, so compare both before switching.
Transparency
Transparent pixels stay transparent in the PDF. A viewer shows the page beneath them, so a logo or a chart exported without a background looks the way it was designed. A 4 KB logo-like PNG with a transparent background made a 6 KB PDF.
Setting quality flattens transparency: JPG cannot store it, so transparent areas are painted white before the image is compressed. Leave quality unset whenever the transparency should survive.
Browser Upload to PDF Download
Plain JavaScript in a web page: the visitor picks screenshots, FormData carries them as repeated file parts, and Accept: application/pdf brings back the PDF itself, saved through a temporary download link.
<input type="file" id="screens" accept="image/png" multiple>
<button id="make-pdf" type="button">Download PDF</button>
<script>
document.getElementById('make-pdf').onclick = async () => {
const form = new FormData();
for (const png of document.getElementById('screens').files) form.append('file', png); // page order
const response = await fetch('https://api.api-ninjas.com/v1/imagetopdf', {
method: 'POST',
headers: { 'X-Api-Key': 'YOUR_API_KEY', 'Accept': 'application/pdf' },
body: form,
});
if (!response.ok) return alert((await response.json()).error); // errors come as JSON
const link = document.createElement('a'); // save the PDF through a temporary link
link.href = URL.createObjectURL(await response.blob());
link.download = 'screenshots.pdf';
link.click();
setTimeout(() => URL.revokeObjectURL(link.href), 1000);
};
</script>A key in page source is visible to anyone, so on a public site make this call from your own server and pass the PDF on to the browser.
Limits
| Pages per PDF | Up to 20, one per PNG |
|---|---|
| PDF returned | About 4 MB; a larger PDF is refused with a hint to set quality |
| Uploads | About 4 MB in total per request |
Images by url | Up to 20 links, 25 MB in total |
| Image size | Up to 120 megapixels each |
Page Size of a Screenshot
With page_size=fit, the default, each page takes the size of its PNG at the resolution stored in the file, or 96 DPI when it stores none, which suits reading on screen. For paper, use a4 or letter, plus a margin if you like: orientation=auto turns a wide screenshot onto a landscape page.
https://api.api-ninjas.com/v1/imagetopdf
Converts one or more PNG images to one PDF, one image per page. Returns the PDF as base64 in JSON, or as a raw PDF file. Accepts GET or POST: use POST to upload images, or GET with url.
Parameters
Send the images as file uploads (multipart form data), as url links, or send one image as the raw request body with its Content-Type, e.g. image/jpeg. The other parameters can be query parameters or multipart form fields.
fileoptionalA PNG image, as a multipart form upload. Repeat
filefor each screenshot or chart: each becomes a page, in the order sent. Up to about 4 MB in total.urloptionalA public
http://orhttps://link to an image. Repeaturlfor more images: up to 20, and 25 MB in total. Uploaded files come first, then theurlimages. Works with GET or POST.page_sizeoptionalfit(default): each page is the size of its image, at the resolution stored in the file.a4,letterorlegal: every page has that size, and each image is scaled to fit inside the margins, keeping its proportions.orientationoptionalauto(default): landscape pages for landscape images and portrait pages for portrait images.portraitorlandscape: every page. Applies only witha4,letterorlegal.marginoptionalWhite margin around each image, in millimeters, from
0to50. Default0.qualityoptionalFrom
1to100. When set, each PNG becomes a JPG page at this quality: the PDF is usually smaller, transparent areas are flattened onto white, and edges of text soften. Default: not set, so each PNG is stored without loss and keeps its transparency.
Headers
X-Api-KeyrequiredAPI Key associated with your account.
Acceptoptionalapplication/pdfreturns the raw PDF file instead of JSON.Content-TypeoptionalThe image type, e.g.
image/jpegorimage/png, when the request body is the image itself. Multipart uploads set their own content type.
Response
The /v1/imagetopdf 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.
sizeSize of the PDF in bytes.
pdfThe PDF file, base64-encoded.
With Accept: application/pdf, the response body is the PDF file itself (Content-Type: application/pdf). Every successful response has an X-Api-Calls-Charged header with the number of API calls the request counted.
Limits
- Up to 20 pages per request (images, plus the extra frames of GIF and TIFF files).
- The PDF can be up to about 4 MB. For larger PDFs, set
quality(for examplequality=75) or send fewer images per request. - Uploads up to about 4 MB in total; images from
urlup to 25 MB in total. - Images up to 120 megapixels.
API Calls
Each page in the PDF counts as 10 API calls: a PDF made from 3 images counts as 30. Requests that fail are not counted. When your remaining quota does not cover every page, the request returns an error and nothing is counted.
Live Demo

Get a free API key to get started — no credit card required.
Press Send to convert the image and preview the PDF here.
The live demo converts one image up to 2 MB. No API key is needed to try it.
Code Examples
# Combine two images into one PDF and save it
curl -X POST "https://api.api-ninjas.com/v1/imagetopdf" \
-H "X-Api-Key: YOUR_API_KEY" \
-H "Accept: application/pdf" \
-F "file=@screenshot-1.png" \
-F "file=@screenshot-2.png" \
--output images.pdfErrors
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 image in the request | Send images as file (multipart form uploads) or as url (links to the images). |
| A file that is not a supported image | Each file must be a JPG, PNG, WebP, GIF, TIFF or BMP image. |
| More than 20 images | Send at most 20 images per request. |
| More than 20 pages, e.g. from a long GIF | The PDF would have 24 pages; the most per request is 20. |
| A PDF over about 4 MB | The PDF would be 5.3 MB; the most one response can return is 4 MB. Send fewer or smaller images, or set quality (for example quality=75) to compress them. |
A page_size other than fit, a4, letter or legal | page_size must be fit, a4, letter or legal. |
A margin out of range | margin must be between 0 and 50 millimeters. |
| An image over 120 megapixels | An image is too large (over 120 megapixels). |
Frequently Asked Questions
Can I use the PNG to PDF API for commercial purposes?
Yes, but you must have a premium subscription. Commercial use of the PNG to PDF 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 PNG to PDF 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 PNG to PDF 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 PNG screenshots to a PDF?
POST them to/v1/imagetopdfas multipartfileparts, one per screenshot in page order, and addAccept: application/pdfto get the PDF file back; without it the PDF comes base64-encoded in JSON. One PNG can also be sent as the raw request body withContent-Type: image/png.Is PNG to PDF conversion lossless?
Yes, unless you setquality. PNGs are stored in the PDF without loss, so text in screenshots and thin lines in diagrams stay sharp: three 2560 x 1800 sample screenshots of 1,374 KB made a 1,374 KB PDF.Does the PDF keep the PNG's transparency?
Yes. Transparent areas stay transparent, and PDF viewers show the white page through them. Settingqualityturns each PNG into a JPG page, which has no transparency, so those areas are flattened onto white.Should I set quality for PNG to PDF?
Only to make the PDF smaller. For screenshots it helps:quality=80took the three sample screenshots from 1,374 KB to 855 KB, with slightly softer text. Charts and diagrams with large flat areas are often smaller as lossless PNG, so compare before switching. A PDF can be up to about 4 MB per request.What page size does a screenshot get in the PDF?
With the defaultpage_size=fit, the page is the size of the image at the resolution stored in the PNG, or 96 DPI when it stores none. For paper, usepage_size=a4orletter, with an optionalmargin;orientation=autoputs wide screenshots on landscape pages.
Explore API integration use cases for recommended APIs and workflow examples.