Image to PDF API
The Image to PDF API converts JPG, PNG and other images to PDF. Send one image or up to 20, as uploads or links, and get back one PDF with one image per page, in the order you sent them. JPG, PNG, WebP, GIF, TIFF and BMP are supported, and every frame of a GIF or multi-page TIFF becomes a page.
Pages can match each image or use a standard paper size (A4, Letter or Legal) with margins, in portrait or landscape. By default images keep their full quality: JPGs are copied into the PDF unchanged and PNGs are stored without loss. Set quality to compress them into a smaller PDF.
Use it to turn scans, receipts, photos and screenshots into a PDF for sharing, printing, archiving or e-signature.
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.
Converting phone photos or scans in JPG? See the JPG to PDF API. To go the other way, the PDF to Image API and PDF to JPG API turn PDF pages into images, and the Image to Text API reads the text in an image.
Available endpoint:
- /v1/imagetopdf - Convert images to one PDF
At a Glance
| Input | JPG, PNG, WebP, GIF, TIFF or BMP: uploads (about 4 MB in total), raw body, or up to 20 links (25 MB in total) |
|---|---|
| Output | One PDF, as base64 in JSON or as a PDF file |
| Pages per request | Up to 20 |
| Page size | Fit to image, A4, Letter or Legal; margins up to 50 mm |
| Image quality | Kept as is, or compressed with quality |
| API calls | 10 per page in the PDF |
Page Sizes
| page_size | Page |
|---|---|
fit | The size of each image (default) |
a4 | 210 x 297 mm |
letter | 8.5 x 11 in |
legal | 8.5 x 14 in |
Related APIs
- PDF to Image API - PDF pages to JPG, PNG or WebP images
- PDF to JPG API - PDF pages to JPG images
- JPG to PDF API - JPG photos and scans to one PDF
- Image to Text API - Read the text in an image (OCR)
https://api.api-ninjas.com/v1/imagetopdf
Converts one or more images (JPG, PNG, WebP, GIF, TIFF or BMP) 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.
fileoptionalAn image, as a multipart form upload. Repeat
fileto add more images: each image becomes a page, in the order sent, and each frame of a GIF or TIFF becomes a page. 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 image is re-encoded as a JPG at this quality to make the PDF smaller, and transparent areas become white. Default: not set, so images are kept as they are: JPGs are copied into the PDF unchanged and PNGs are stored without loss.
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?page_size=a4&margin=10" \
-H "X-Api-Key: YOUR_API_KEY" \
-H "Accept: application/pdf" \
-F "file=@photo.jpg" \
-F "file=@scan.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 Image to PDF API for commercial purposes?
Yes, but you must have a premium subscription. Commercial use of the Image 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 Image 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 Image 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 images to PDF with an API?
Send the images to/v1/imagetopdfas multipart uploads namedfile(repeat it for each image), asurllinks, or send one image as the raw request body. The response is JSON with the PDF base64-encoded inpdf; add the headerAccept: application/pdfto get the PDF file itself. For JPG photos, see the JPG to PDF API.Can I combine multiple images into one PDF?
Yes. Send up to 20 images in one request and you get one PDF with one image per page, in the order you sent them. Each frame of a GIF or multi-page TIFF becomes its own page, and counts toward the 20 pages.Which image formats can I convert to PDF?
JPG, PNG, WebP, GIF, TIFF and BMP, in any mix. Transparent PNGs keep their transparency unless you setquality, which places them on white.Does converting images to PDF reduce their quality?
No, not by default: JPGs are copied into the PDF unchanged and PNGs are stored without loss, so the pages look exactly like your images. Setquality(1 to 100) only when you want a smaller PDF; every image is then compressed again as a JPG at that quality.How do I make A4 or Letter pages with margins?
Setpage_sizetoa4,letterorlegaland addmarginin millimeters, e.g./v1/imagetopdf?page_size=a4&margin=10. Each image is scaled to fit inside the margins and keeps its proportions.orientation=auto(the default) turns the page to match each image;portraitorlandscapefixes it.How many API calls does Image to PDF use?
Each page in the PDF counts as 10 API calls, so a PDF made from 3 images counts as 30. Requests that fail are not counted, and theX-Api-Calls-Chargedresponse header shows the count for each request. To read text from images instead, see the Image to Text API.
Explore API integration use cases for recommended APIs and workflow examples.