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

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

  1. Upload the JPGs in one multipart request.Add one file part 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 repeated url parameters instead, up to 25 MB together.
  2. Choose page_size and margin.With the default fit, every page is exactly the size of its photo, which suits reading on screen. For a PDF that prints cleanly, pick a4, letter or legal and add a margin in millimeters, e.g. page_size=letter&margin=10. Each photo is scaled to sit inside the border, and orientation=auto gives 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:

SettingsPDF sizeRelative size
None: photos copied as they are823 KB
quality=75672 KB
quality=60 with page_size=a4581 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.pdf

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

  • file  optional

    A JPG photo or scan, as a multipart form upload. Repeat file for each photo: 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 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-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).

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.

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

Live demo · no API key required
Form data and query parameters
file
Selected file
Using the sample photo until you choose a file.
page_size
margin

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?page_size=a4&margin=10
Sample response

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

{
"page_count": 1,
"size": 70116,
"pdf": "JVBERi0xLjMKJeLjz9MKMSAwIG9iago8PAogICAgL0NyZWF0..."
}

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.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 JPG 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.
  • Send them in one multipart request to /v1/imagetopdf, one file part 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 repeated url parameters.
  • 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 set quality.
  • 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. When quality is set, the photo is rotated before it is compressed again.
  • Set quality to re-encode every photo as a JPG at that quality. With the three sample photos, quality=75 gave 672 KB instead of 823 KB, and quality=60 on A4 pages 581 KB. A PDF can be up to about 4 MB, so large batches of full-resolution photos need quality or several requests.
  • 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, add page_size=letter or a4 and a margin.