NewConnect Claude, Gemini, ChatGPT, and other AI agents to API Ninjas via our MCP server →

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 PDFUp to 20, one per PNG
PDF returnedAbout 4 MB; a larger PDF is refused with a hint to set quality
UploadsAbout 4 MB in total per request
Images by urlUp to 20 links, 25 MB in total
Image sizeUp 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.

  • file  optional

    A PNG image, as a multipart form upload. Repeat file for each screenshot or chart: each becomes a page, in the order sent. Up to about 4 MB in total.

  • url  optional

    A public http:// or https:// link to an image. Repeat url for more images: up to 20, and 25 MB in total. Uploaded files come first, then the url images. Works with GET or POST.

  • page_size  optional

    fit (default): each page is the size of its image, at the resolution stored in the file. a4, letter or legal: every page has that size, and each image is scaled to fit inside the margins, keeping its proportions.

  • orientation  optional

    auto (default): landscape pages for landscape images and portrait pages for portrait images. portrait or landscape: every page. Applies only with a4, letter or legal.

  • margin  optional

    White margin around each image, in millimeters, from 0 to 50. Default 0.

  • quality  optional

    From 1 to 100. 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-Key  required

    API Key associated with your account.

  • Accept  optional

    application/pdf returns the raw PDF file instead of JSON.

  • Content-Type  optional

    The image type, e.g. image/jpeg or image/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_count

    Number of pages in the PDF.

  • size

    Size of the PDF in bytes.

  • pdf

    The 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 example quality=75) or send fewer images per request.
  • Uploads up to about 4 MB in total; images from url up 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

Live demo · no API key required
Form data and query parameters
file
Selected file
Using the sample chart (a PNG with a transparent background) until you choose a file.
page_size
quality

Get a free API key to get started — no credit card required.

Headers
X-Api-KeyLog in or sign up to get your API key
POST
https://api.api-ninjas.com/v1/imagetopdf
Sample response

Press Send to convert the image and preview the PDF here.

{
"page_count": 1,
"size": 20416,
"pdf": "JVBERi0xLjQKJeLjz9MKMSAwIG9iago8PAogICAgL0NyZWF0..."
}

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.pdf

Errors

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.

CauseExample error
No image in the requestSend images as file (multipart form uploads) or as url (links to the images).
A file that is not a supported imageEach file must be a JPG, PNG, WebP, GIF, TIFF or BMP image.
More than 20 imagesSend at most 20 images per request.
More than 20 pages, e.g. from a long GIFThe PDF would have 24 pages; the most per request is 20.
A PDF over about 4 MBThe 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 legalpage_size must be fit, a4, letter or legal.
A margin out of rangemargin must be between 0 and 50 millimeters.
An image over 120 megapixelsAn image is too large (over 120 megapixels).

Frequently Asked Questions

  • 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.
  • Sign up for a free account to instantly get your API key, then pass it in the X-Api-Key header on every request. The documentation above includes ready-to-run examples in cURL, Python, JavaScript, Node.js, and more.
  • 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.
  • 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.
  • POST them to /v1/imagetopdf as multipart file parts, one per screenshot in page order, and add Accept: application/pdf to 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 with Content-Type: image/png.
  • Yes, unless you set quality. 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.
  • Yes. Transparent areas stay transparent, and PDF viewers show the white page through them. Setting quality turns each PNG into a JPG page, which has no transparency, so those areas are flattened onto white.
  • Only to make the PDF smaller. For screenshots it helps: quality=80 took 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.
  • With the default page_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, use page_size=a4 or letter, with an optional margin; orientation=auto puts wide screenshots on landscape pages.