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

PDF to JPG API

The PDF to JPG API converts PDF pages to JPG images with one API call. Upload a PDF or pass a link to one, choose the pages, the resolution and the JPG quality, and get each page back as a JPG: base64-encoded in JSON, with the page's size and text, or as a .jpg file.

PDF to JPG is served by the PDF to Image API endpoint /v1/pdftoimage with format=jpg, the default, so every example on this page uses format=jpg.

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.

When to Choose JPG

JPG is the most widely supported image format, and it keeps files small for scanned pages and pages with photos. Choose it for thumbnails and previews, document viewers, email and chat attachments, and as input for OCR.

JPG compression can leave faint artifacts around sharp text and thin lines. For pixel-exact text, line art and diagrams, choose PNG (lossless, larger files); for the smallest files on the web, choose WebP. Both are covered on the PDF to Image API page.

Quality and File Size

quality (1 to 100, default 85) sets how strongly each JPG is compressed. 85 keeps text crisp on screen at a moderate size. Going down to 60 makes a typical text page roughly a quarter smaller, with softer edges around letters; going up to 95 makes it roughly a third larger. Quality 100 makes much larger files for little visible gain.

Resolution costs more than quality: each step up in dpi adds pixels, and doubling the DPI roughly triples the size of a text page. Use 72 DPI for thumbnails, the default 150 DPI for reading on screen, and 300 DPI for printing or OCR.

JPG Size per Page

Typical sizes for a text page at the default quality=85:

dpiUS Letter pageTypical JPG size
72612 x 792 px75 to 120 KB
1501275 x 1650 px250 to 350 KB
3002550 x 3300 px700 to 900 KB

Pages with large photos or dark backgrounds come out larger, and mostly blank pages smaller. One response carries up to about 4 MB of images, so at 300 DPI around four text pages fit; continue from next_page for the rest.

Which Quality to Use

qualityGood for
60-75Thumbnails, previews and large batches where size matters most
85Reading on screen and OCR (default)
90-95Printing and archiving

Related APIs

https://api.api-ninjas.com/v1/pdftoimage

Converts the pages of a PDF to JPG images. Returns each page as a base64 image with its size and its text, or one page as a raw image file. Accepts GET or POST: use POST to upload the PDF, or GET with url.

Parameters

Send the PDF in one of three ways: as file (a multipart form upload), as url, or as the raw request body with Content-Type: application/pdf (up to about 4 MB). The other parameters can be query parameters or multipart form fields.

  • file  optional

    The PDF, as a multipart form upload (multipart/form-data), up to about 4 MB. Send one PDF per request.

  • url  optional

    A public http:// or https:// link to the PDF, up to 25 MB, e.g. https://example.com/report.pdf. Works with GET or POST.

  • pages  optional

    The pages to convert: one page (1), a range (2-5), a list (1,3,7-9) or a range to the end (4-, page 4 to the last page). Page 1 is the first page. Default: every page, up to 10 per request (see limits).

  • format  optional

    Image format: jpg (default), png or webp. The examples on this page use format=jpg; see the PDF to Image API for PNG and WebP.

  • dpi  optional

    Resolution in dots per inch, from 30 to 300. Default 150. At 150 DPI a US Letter page is about 1275 x 1650 pixels; at 300 DPI, 2550 x 3300.

  • quality  optional

    Image quality for jpg and webp, from 1 to 100. Default 85. Lower values make smaller files with more compression artifacts. Ignored for png, which is lossless.

  • password  optional

    The password of a password-protected PDF.

Headers

  • X-Api-Key  required

    API Key associated with your account.

  • Accept  optional

    image/jpeg or image/* returns the first requested page as a raw image file instead of JSON.

  • Content-Type  optional

    application/pdf when the request body is the PDF itself. Multipart uploads set their own content type.

Response

The /v1/pdftoimage 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.

  • next_page

    The next requested page that is not in this response, because of the per-request limits, or null when every requested page was returned. To continue, send the same request with pages starting at next_page, e.g. pages=11-.

  • pages

    The converted pages, in the order requested, each with the fields below.

  • pages[].page

    Page number in the PDF (1 is the first page).

  • pages[].format

    jpg, png or webp.

  • pages[].width, pages[].height

    Image size in pixels.

  • pages[].text

    The text on the page, as plain text. Empty for scanned pages, whose text is part of an image; to read those, send the page image to the Image to Text API.

  • pages[].image

    The image file, base64-encoded.

With an image Accept header, the response body is the raw image of the first requested page, with Content-Type image/jpeg. Every successful response has an X-Api-Calls-Charged header with the number of API calls the request counted.

Limits

  • Up to 10 pages per request.
  • Each response carries up to about 4 MB of images. At high DPI fewer pages fit (around four text pages at 300 DPI); the rest are left for the next request, from next_page.
  • Pages wider or taller than 5,000 pixels, or larger than 12 megapixels, at the requested DPI are scaled down to fit.
  • Uploads up to about 4 MB; PDFs from url up to 25 MB.

API Calls

Each page returned counts as 10 API calls: a response with 3 pages counts as 30. Requests that fail are not counted. If your remaining quota covers fewer pages than you asked for, the response returns the pages it covers, and next_page points at the rest.

Live Demo

Live demo · no API key required
Form data and query parameters
file
Using the sample invoice PDF (2 pages) until you choose a file.
pages
format
dpi
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/pdftoimage?pages=1&format=jpg&dpi=150&quality=85
Sample response
Page 1 of the PDF as JPG
Page 1: 1275 x 1651 px JPG
{
"page_count": 2,
"next_page": null,
"pages": [
{
"page": 1,
"format": "jpg",
"width": 1275,
"height": 1651,
"text": "INVOICE Example Supplies Ltd.\n100 Example Street\nSpringfield, ST 00000\nInvoice number INV-1042\nInvoice date 2026-11-04\nDue date 2026-12-04\nBill to\nSample Customer Inc.\n200 Sample Avenue\nRiverside, ST 00000\nItem Qty Unit price Amount\nCopy paper, 500 sheets 10 6.50 65.00\nToner cartridge 2 48.00 96.00\nDesk organizer 3 12.00 36.00\nBallpoint pens, box of 12 5 4.20 21.00\nSubtotal 218.00\nTax (8%) 17.44\nTotal due USD 235.44\nThank you for your business. Page 1 of 2",
"image": "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAUDBAQEAwUEBAQFBQUGBwwIBwcH..."
}
]
}

The live demo converts one page at up to 150 DPI, from PDFs up to 2 MB. No API key is needed to try it.

Code Examples

# Convert pages of document.pdf; the JSON holds each page as a base64 image curl -X POST "https://api.api-ninjas.com/v1/pdftoimage?pages=1-3&format=jpg&dpi=150&quality=85" \ -H "X-Api-Key: YOUR_API_KEY" \ -F "file=@document.pdf" # Or save page 1 as a JPG file curl -X POST "https://api.api-ninjas.com/v1/pdftoimage?pages=1&format=jpg&dpi=150&quality=85" \ -H "X-Api-Key: YOUR_API_KEY" \ -H "Accept: image/jpeg" \ -F "file=@document.pdf" \ --output page-1.jpg

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 PDF in the requestSend a PDF as file (a multipart form upload) or as url (a link to the PDF).
The file is not a PDFThe file is not a PDF.
A password-protected PDF without passwordThis PDF is password-protected. Send its password in the password parameter.
A wrong passwordThe password is incorrect for this PDF.
pages outside the PDF, e.g. pages=5 for a 3-page PDFpages is outside this PDF, which has 3 pages.
A pages value that is not a page listpages must be page numbers or ranges such as 1, 2-5, 1,3,7-9 or 4- (page 4 to the end).
A format other than jpg, png or webpformat must be jpg, png or webp.
A number out of range, e.g. dpi=600dpi must be between 30 and 300.
A PDF at url over 25 MBThe PDF at url is larger than 25 MB.
One page alone is too large for a responsePage 1 is too large to return at 300 DPI as PNG. Use a lower dpi or format=jpg.

Frequently Asked Questions

  • Yes, but you must have a premium subscription. Commercial use of the PDF to JPG 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 the PDF to /v1/pdftoimage with format=jpg (the default): as a multipart upload named file, as the raw request body, or as a url. For example, curl -X POST "https://api.api-ninjas.com/v1/pdftoimage?pages=1-3&format=jpg" -H "X-Api-Key: YOUR_API_KEY" -F "file=@document.pdf" returns pages 1 to 3 as base64 JPGs in JSON. Add the header Accept: image/jpeg to get the first page as a .jpg file instead.
  • One request converts up to 10 pages to JPG (fewer at high DPI, as a response carries up to about 4 MB of images). If pages are left over, the response's next_page says where to continue: repeat the request with pages=<next_page>- until next_page is null. To convert many PDFs, send one request per PDF; requests can run in parallel.
  • The default quality=85 keeps text crisp on screen at a moderate size and suits most uses, including OCR. Use 60 to 75 for thumbnails and previews, where a smaller file matters more than fine detail, and 90 to 95 for printing and archiving. Quality 100 makes much larger files for little visible gain.
  • For a typical text page at quality=85: about 75 to 120 KB at 72 DPI, 250 to 350 KB at 150 DPI (the default), and 700 to 900 KB at 300 DPI. Pages with photos or dark backgrounds come out larger. Lowering dpi saves far more than lowering quality.
  • JPG for most uses: smaller files, supported everywhere, and good for scans and photos. PNG when text and line art must stay pixel-exact, at a larger file size. Both, plus WebP, are available from the same endpoint; see the PDF to Image API.
  • Each JPG page returned counts as 10 API calls, so a 3-page PDF counts as 30. Requests that fail are not counted, and the X-Api-Calls-Charged response header shows the count for each request.