JPG to PDF API
The JPG to PDF API converts JPG images to PDF with one API call. Send up to 20 JPGs, as uploads or links, and get back one PDF with one image per page, in the order you sent them, as base64 in JSON or as a PDF file.
JPG to PDF is served by the Image to PDF API endpoint /v1/imagetopdf, which also takes PNG, WebP, GIF, TIFF and BMP images.
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.
No Quality Loss
Each JPG is copied into the PDF as it is, without being decoded and compressed again, so the pages look exactly like your images and the PDF is about the same size as the JPGs together. Photos taken sideways are shown upright, following the orientation the camera stored in the file.
Smaller PDFs from Phone Photos
Full-resolution phone and camera photos are often several megabytes each, and one response can return a PDF of up to about 4 MB. Set quality (1 to 100) to compress every image again as a JPG at that quality: quality=75 often makes high-quality photos several times smaller while still looking sharp on screen. Leave it unset to keep the original images.
Page Sizes and Margins
By default (page_size=fit) each page is the size of its image. For pages you can print, set page_size to a4, letter or legal: each photo is scaled to fit the page and keeps its proportions, and with orientation=auto landscape photos get landscape pages. Add margin (0 to 50 mm) for a white border.
Common Settings
| Goal | Parameters |
|---|---|
| Keep the photos exactly as they are | none (defaults) |
| Printable A4 pages with a border | page_size=a4&margin=10 |
| US Letter pages, always portrait | page_size=letter&orientation=portrait |
| A smaller PDF from phone photos | quality=75 |
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
- Image to PDF API - JPG, PNG and other images 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 JPG 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.
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, e.g.quality=75for phone photos. Default: not set, so each JPG is copied into the PDF unchanged.
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-1.jpg" \
-F "file=@photo-2.jpg" \
--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 JPG to PDF API for commercial purposes?
Yes, but you must have a premium subscription. Commercial use of the JPG 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 JPG 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 JPG 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 JPG to PDF with an API?
Send the JPGs to/v1/imagetopdfas multipart uploads namedfile, e.g.curl -X POST "https://api.api-ninjas.com/v1/imagetopdf" -H "X-Api-Key: YOUR_API_KEY" -H "Accept: application/pdf" -F "file=@photo-1.jpg" -F "file=@photo-2.jpg" --output photos.pdf. You can also passurllinks or send one JPG as the raw request body. The same endpoint converts PNG and other formats; see the Image to PDF API.Does converting JPG to PDF lose quality?
No. Each JPG is copied into the PDF without being compressed again, so the pages look exactly like the photos and the PDF is about the same size as the JPGs together. Quality only changes if you setqualityto make the PDF smaller.How do I batch convert JPGs into one PDF?
Send up to 20 JPGs in one request; they become the pages of one PDF in the order you sent them. The PDF can be up to about 4 MB, so for many large photos setqualityor split them across requests, each of which returns its own PDF.How do I make a PDF from phone photos smaller?
Setquality, e.g.quality=75: every photo is compressed again as a JPG at that quality, which often makes full-resolution photos several times smaller while they still look sharp on screen. Photos taken sideways stay upright either way.How do I put JPGs on A4 or Letter pages?
Usepage_size=a4(orletterorlegal) and, for a white border,marginin millimeters, e.g.page_size=a4&margin=10. Each photo is scaled to fit the page and keeps its proportions; withorientation=auto, the default, landscape photos get landscape pages.How many API calls does converting JPG to PDF use?
Each page in the PDF counts as 10 API calls, so a PDF of 3 JPGs counts as 30. Requests that fail are not counted, and theX-Api-Calls-Chargedresponse header shows the count for each request.
Explore API integration use cases for recommended APIs and workflow examples.