JPG to PDF API
A phone is the scanner most people carry. Receipts for an expense claim, the signed pages of a lease, delivery notes, a whiteboard after a meeting: they all start as JPGs in a camera roll and usually have to leave as a single PDF. The JPG to PDF API does that join in one request.
Requests go to /v1/imagetopdf, the Image to PDF API endpoint, which takes PNG, WebP, GIF, TIFF and BMP files as well.
Each page uses one of your plan's monthly document pages, not API calls: Free 50, Developer 10,000, Business 100,000, Professional 500,000. Requests that fail are not counted. Your dashboard shows the pages you've used this month. See pricing.
Photos to One PDF in Two Steps
- Upload the JPGs in one multipart request.Add one
filepart per photo, in the order the pages should run: up to 20 photos and about 4 MB in total. Photos that are already online can be passed as repeatedurlparameters instead, up to 25 MB together. - Choose
page_sizeandmargin.With the defaultfit, every page is exactly the size of its photo, which suits reading on screen. For a PDF that prints cleanly, picka4,letterorlegaland add amarginin millimeters, e.g.page_size=letter&margin=10. Each photo is scaled to sit inside the border, andorientation=autogives landscape shots a landscape page.
The finished PDF comes back base64-encoded in JSON, with page_count and size, or as the file itself when you send Accept: application/pdf.
Your JPGs Go In Unchanged
Nothing is decoded and compressed a second time. The bytes of each JPG are copied straight into the PDF, so there is no generation loss: zoom in and you see exactly the pixels the camera saved, and the PDF weighs barely more than the photos.
Phones often store a picture sideways and note which way is up in its orientation tag. That tag is honoured: the page is turned to match, so a receipt shot upright reads upright, without the photo's pixels being rewritten. (With quality set, the photo is rotated before it is compressed again.)
Size Example
Three sample phone photos, 809 KB together, as one PDF:
| Settings | PDF size | Relative size |
|---|---|---|
| None: photos copied as they are | 823 KB | |
quality=75 | 672 KB | |
quality=60 with page_size=a4 | 581 KB |
Measured on sample photos. The untouched PDF adds about 2% for the PDF's own structure. quality re-encodes every photo, so keep it for when the PDF has to shrink, for example to stay under the limit of about 4 MB per PDF.
Send Several JPGs with cURL
Repeat -F file=@... once per photo; the order of the parts is the order of the pages. Three receipts become a Letter-size PDF with a 10 mm white border, written straight to a file:
# Three receipts photographed on a phone -> one Letter-size PDF with a 10 mm border
curl -X POST "https://api.api-ninjas.com/v1/imagetopdf?page_size=letter&margin=10" \
-H "X-Api-Key: YOUR_API_KEY" \
-H "Accept: application/pdf" \
-F "file=@receipt-taxi.jpg" \
-F "file=@receipt-hotel.jpg" \
-F "file=@receipt-dinner.jpg" \
--output expenses-march.pdfA PDF made from receipts holds pictures of the text, not text you can search. To read the totals and dates, send the same photos to the Image to Text API.
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.
fileoptionalA JPG photo or scan, as a multipart form upload. Repeat
filefor each photo: 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 photo is re-encoded as a JPG at this quality to make the PDF smaller, e.g.quality=75. 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).
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.
Document pages
This API uses your plan's monthly document pages, not API calls. Each page in the PDF uses one: a PDF made from 3 images uses 3. Requests that fail are not 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 combine several JPGs into one PDF?
Send them in one multipart request to/v1/imagetopdf, onefilepart per photo in page order, 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=@page-1.jpg" -F "file=@page-2.jpg" --output pages.pdf. Up to 20 photos per request; photos already online can be passed as repeatedurlparameters.Will my photos lose quality in the PDF?
No. Each JPG is copied into the PDF byte for byte, without being compressed again, so the PDF is only slightly larger than the photos: three sample phone photos of 809 KB made an 823 KB PDF. Quality changes only if you setquality.Why do photos I took sideways come out upright?
Phones record which way is up in each photo's orientation tag, and the API turns the page to match it, so the photo's own data stays untouched. Whenqualityis set, the photo is rotated before it is compressed again.How can I make a PDF of phone photos smaller?
Setqualityto re-encode every photo as a JPG at that quality. With the three sample photos,quality=75gave 672 KB instead of 823 KB, andquality=60on A4 pages 581 KB. A PDF can be up to about 4 MB, so large batches of full-resolution photos needqualityor several requests.Can I turn photographed receipts into a searchable PDF?
The PDF holds the receipts as images, which you can print, file or attach, but its text is not searchable. To read the merchant, date and total, send the same photos to the Image to Text API. For printable pages, addpage_size=letterora4and amargin.
Explore API integration use cases for recommended APIs and workflow examples.