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

PDF to JPG API

Most PDFs end up as a JPG somewhere: the thumbnail in a document library, the cover image shown after an upload, the page pasted into an email or a chat. The PDF to JPG API makes those images in one call. Send a PDF, or a link to one, and get its pages back as JPGs sized and compressed for where they will be shown.

It runs on /v1/pdftoimage, the PDF to Image API endpoint, where JPG is the default format, so no format parameter is needed. Every JPG arrives with the page's width, height and text in JSON; add Accept: image/jpeg to receive a single page as the .jpg file itself.

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.

Previews, Thumbnails and Attachments

  • Document library thumbnails. dpi=72 with quality=70 turns a Letter page into a 612 x 792 px image that loads quickly in a grid of dozens.
  • Cover image after an upload. Request pages=1 with Accept: image/jpeg and store the bytes next to the PDF.
  • Email and chat attachments. A JPG opens inline in mail clients and messaging apps, where a PDF needs a separate viewer. The default 150 DPI reads well on phones and laptops.
  • Listings and galleries. Show brochures, menus, flyers and catalog pages as ordinary images on product and listing pages.

JPG Quality vs File Size

quality runs from 1 to 100 and defaults to 85. One text page at 150 DPI, measured at four settings (sizes rounded):

qualityJPG sizevs. default
50190 KB40% smaller
70240 KB25% smaller
85 (default)310 KB-
95470 KB50% larger

Compression shows first as faint speckles around the strokes of letters, which a small thumbnail hides. That makes 60 to 70 a good choice for previews, 85 right for pages people read, and 90 to 95 the setting for archives and printing.

Picking a DPI: Screens vs Print

DPI decides how many pixels each JPG has, and it moves the file size much more than quality does. Doubling it from 150 to 300 makes a text page about 2.5 times larger, while dropping quality from 85 to 70 saves about a quarter. Choose it for the screen or the printer the image is meant for:

Shown ondpiLetter pageText pagePhoto page
Thumbnail grids and link previews72612 x 792 pxabout 120 KBabout 40 KB
Phones, laptops, email and chat150 (default)1275 x 1650 pxabout 360 KBabout 140 KB
Printing at full size, zooming in3002550 x 3300 pxabout 920 KBabout 450 KB

Sizes are per page at the default quality, measured on sample documents: a text-heavy contract and pages of photos, which JPG compresses especially well. A screen seldom needs more than 150 DPI, since a 1275-pixel-wide page already fills a laptop window, while 300 DPI prints a page at its real size with no visible pixels. Large sheets such as posters and drawings are scaled down to fit 5,000 pixels a side.

Convert a Long PDF, Page by Page

One request returns up to 10 pages, and fewer once the JPGs reach about 4 MB (around four text pages at 300 DPI). The response's next_page says where to pick up. This Python loop keeps asking from that page until next_page is null, writing page-1.jpg, page-2.jpg and so on:

# pip install requests import base64, requests pdf = open('handbook.pdf', 'rb').read() next_page = 1 # start at page 1; each response says where to continue while next_page is not None: response = requests.post( 'https://api.api-ninjas.com/v1/pdftoimage', params={'pages': f'{next_page}-', 'dpi': '150', 'quality': '80'}, headers={'X-Api-Key': 'YOUR_API_KEY'}, files={'file': ('handbook.pdf', pdf, 'application/pdf')}, timeout=60, ) response.raise_for_status() batch = response.json() for page in batch['pages']: # page-1.jpg, page-2.jpg, ... with open(f"page-{page['page']}.jpg", 'wb') as out: out.write(base64.b64decode(page['image'])) next_page = batch['next_page'] # None after the last page

For a large PDF that is already online, pass it as url instead of file so it is not uploaded again on every loop.

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

Converts the pages of a PDF to JPG images; JPG is the default format. 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).

  • 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

    JPG quality, from 1 to 100. Default 85. Lower values make smaller files with more compression artifacts.

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

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.

Document pages

This API uses your plan's monthly document pages, not API calls. Each page returned uses one: a response with 3 pages uses 3. Requests that fail are not counted. If you have fewer pages left than you asked for, the response returns the pages left, 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
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&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&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&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.
  • POST the PDF to /v1/pdftoimage as a multipart upload named file, as the raw request body with Content-Type: application/pdf, or pass a url. JPG is the default format, so no format parameter is needed: curl -X POST "https://api.api-ninjas.com/v1/pdftoimage?pages=1-3" -H "X-Api-Key: YOUR_API_KEY" -F "file=@document.pdf" returns pages 1 to 3 as base64 JPGs in JSON, each with its width, height and text.
  • Request pages=1&dpi=72 and send the header Accept: image/jpeg: the response body is the JPG itself, 612 x 792 pixels for a US Letter page, ready to store as the document's preview. Add quality=70 for an even smaller file; a thumbnail hides the extra compression.
  • The default, 85, suits pages people read. On a sample text page at 150 DPI, quality 50 made about 190 KB, 70 about 240 KB, 85 about 310 KB and 95 about 470 KB. Choose 60 to 70 for previews and thumbnails, and 90 to 95 for archiving or printing.
  • 300 DPI, which prints a page at its actual size: a US Letter page becomes 2550 x 3300 pixels, about 920 KB as a JPG for a text page. Screens rarely need more than the default 150 DPI. Because one response carries about 4 MB of images, expect around four 300 DPI text pages per request.
  • Each request returns up to 10 pages, fewer when the images reach about 4 MB. Repeat the request with pages=<next_page>- until next_page in the response is null; page_count gives the total up front. The Python example on this page does exactly that and saves page-1.jpg, page-2.jpg and so on.