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=72withquality=70turns 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=1withAccept: image/jpegand 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):
| quality | JPG size | vs. default |
|---|---|---|
50 | 190 KB | 40% smaller |
70 | 240 KB | 25% smaller |
85 (default) | 310 KB | - |
95 | 470 KB | 50% 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 on | dpi | Letter page | Text page | Photo page |
|---|---|---|---|---|
| Thumbnail grids and link previews | 72 | 612 x 792 px | about 120 KB | about 40 KB |
| Phones, laptops, email and chat | 150 (default) | 1275 x 1650 px | about 360 KB | about 140 KB |
| Printing at full size, zooming in | 300 | 2550 x 3300 px | about 920 KB | about 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 pageFor 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.
fileoptionalThe PDF, as a multipart form upload (
multipart/form-data), up to about 4 MB. Send one PDF per request.urloptionalA public
http://orhttps://link to the PDF, up to 25 MB, e.g.https://example.com/report.pdf. Works with GET or POST.pagesoptionalThe 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).dpioptionalResolution in dots per inch, from
30to300. Default150. At 150 DPI a US Letter page is about 1275 x 1650 pixels; at 300 DPI, 2550 x 3300.qualityoptionalJPG quality, from
1to100. Default85. Lower values make smaller files with more compression artifacts.passwordoptionalThe password of a password-protected PDF.
Headers
X-Api-KeyrequiredAPI Key associated with your account.
Acceptoptionalimage/jpegorimage/*returns the first requested page as a raw image file instead of JSON.Content-Typeoptionalapplication/pdfwhen 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_countNumber of pages in the PDF.
next_pageThe next requested page that is not in this response, because of the per-request limits, or
nullwhen every requested page was returned. To continue, send the same request withpagesstarting atnext_page, e.g.pages=11-.pagesThe converted pages, in the order requested, each with the fields below.
pages[].pagePage number in the PDF (1 is the first page).
pages[].formatjpg,pngorwebp.pages[].width, pages[].heightImage size in pixels.
pages[].textThe 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[].imageThe 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
urlup 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
Get a free API key to get started — no credit card required.

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.jpgErrors
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 PDF in the request | Send a PDF as file (a multipart form upload) or as url (a link to the PDF). |
| The file is not a PDF | The file is not a PDF. |
A password-protected PDF without password | This PDF is password-protected. Send its password in the password parameter. |
A wrong password | The password is incorrect for this PDF. |
pages outside the PDF, e.g. pages=5 for a 3-page PDF | pages is outside this PDF, which has 3 pages. |
A pages value that is not a page list | pages 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 webp | format must be jpg, png or webp. |
A number out of range, e.g. dpi=600 | dpi must be between 30 and 300. |
A PDF at url over 25 MB | The PDF at url is larger than 25 MB. |
| One page alone is too large for a response | Page 1 is too large to return at 300 DPI as PNG. Use a lower dpi or format=jpg. |
Frequently Asked Questions
Can I use the PDF to JPG API for commercial purposes?
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.How do I get an API key and start using the PDF to JPG 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 PDF to JPG 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 a PDF to JPG with an API?
POST the PDF to/v1/pdftoimageas a multipart upload namedfile, as the raw request body withContent-Type: application/pdf, or pass aurl. JPG is the default format, so noformatparameter 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.How do I make a JPG thumbnail of a PDF's first page?
Requestpages=1&dpi=72and send the headerAccept: 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. Addquality=70for an even smaller file; a thumbnail hides the extra compression.What JPG quality setting should I use?
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.What DPI makes JPGs good enough to print?
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.How do I convert every page of a long PDF to JPG?
Each request returns up to 10 pages, fewer when the images reach about 4 MB. Repeat the request withpages=<next_page>-untilnext_pagein the response isnull;page_countgives the total up front. The Python example on this page does exactly that and saves page-1.jpg, page-2.jpg and so on.
Explore API integration use cases for recommended APIs and workflow examples.