Back to API Docs
POSThttps://app.alternapdf.com/api/v1/convert/pdf-to-image

PDF to Image

Render PDF pages as high-quality images. Supports PNG, JPEG, and WebP output formats with configurable DPI, quality, and dimensions. Request a single page to receive an image file directly, or a page range to receive a ZIP archive containing all rendered pages.

Content-Type: multipart/form-data

Parameters

ParameterTypeDefaultDescription
file requiredfileThe PDF file to render as images.
page_numberinteger1Render a single specific page. Use this for single-page output.
start_pageintegerFirst page of a range to render. Used with end_page for multi-page output (ZIP).
end_pageintegerLast page of a range to render. Used with start_page for multi-page output (ZIP).
image_formatstringPNGOutput image format. Options: PNG, JPEG, WEBP.
dpiinteger150Resolution in dots per inch. Options: 72, 150, 300.
qualityinteger85Image quality (1-100). Applies to JPEG and WebP formats.
transparent_backgroundbooleanfalseUse a transparent background instead of white. PNG format only.
custom_widthintegerCustom output width in pixels. Aspect ratio is maintained if only width is set.
custom_heightintegerCustom output height in pixels. Aspect ratio is maintained if only height is set.

Code Examples

cURL
# Single page - returns an image file
curl -X POST "https://app.alternapdf.com/api/v1/convert/pdf-to-image" \
  -H "X-API-Key: YOUR_API_KEY" \
  -F "file=@document.pdf" \
  -F "page_number=1" \
  -F "image_format=PNG" \
  -F "dpi=300" \
  --output page1.png

# Multiple pages - returns a ZIP archive
curl -X POST "https://app.alternapdf.com/api/v1/convert/pdf-to-image" \
  -H "X-API-Key: YOUR_API_KEY" \
  -F "file=@document.pdf" \
  -F "start_page=1" \
  -F "end_page=5" \
  -F "image_format=JPEG" \
  -F "quality=90" \
  --output pages.zip
Python
import requests

url = "https://app.alternapdf.com/api/v1/convert/pdf-to-image"
headers = {"X-API-Key": "YOUR_API_KEY"}

# Single page rendering
with open("document.pdf", "rb") as f:
    files = {"file": ("document.pdf", f, "application/pdf")}
    data = {
        "page_number": "1",
        "image_format": "PNG",
        "dpi": "300",
    }
    response = requests.post(url, headers=headers, files=files, data=data)

with open("page1.png", "wb") as out:
    out.write(response.content)

# Multi-page rendering (returns ZIP)
with open("document.pdf", "rb") as f:
    files = {"file": ("document.pdf", f, "application/pdf")}
    data = {
        "start_page": "1",
        "end_page": "5",
        "image_format": "JPEG",
        "quality": "90",
    }
    response = requests.post(url, headers=headers, files=files, data=data)

with open("pages.zip", "wb") as out:
    out.write(response.content)
JavaScript
import fs from "fs";

const formData = new FormData();
formData.append("file", fs.createReadStream("document.pdf"));
formData.append("page_number", "1");
formData.append("image_format", "PNG");
formData.append("dpi", "300");

const response = await fetch("https://app.alternapdf.com/api/v1/convert/pdf-to-image", {
  method: "POST",
  headers: {
    "X-API-Key": "YOUR_API_KEY",
  },
  body: formData,
});

const buffer = await response.arrayBuffer();
fs.writeFileSync("page1.png", Buffer.from(buffer));

// Multi-page rendering (returns ZIP)
const multiFormData = new FormData();
multiFormData.append("file", fs.createReadStream("document.pdf"));
multiFormData.append("start_page", "1");
multiFormData.append("end_page", "5");
multiFormData.append("image_format", "JPEG");
multiFormData.append("quality", "90");

const multiResponse = await fetch("https://app.alternapdf.com/api/v1/convert/pdf-to-image", {
  method: "POST",
  headers: {
    "X-API-Key": "YOUR_API_KEY",
  },
  body: multiFormData,
});

const zipBuffer = await multiResponse.arrayBuffer();
fs.writeFileSync("pages.zip", Buffer.from(zipBuffer));

Response

The response format depends on the number of pages requested:

Single Page

Returns the image file directly as a binary response.

HeaderValue
Content-Typeimage/png, image/jpeg, or image/webp
Content-Dispositionattachment; filename="page_1.png"

Multiple Pages

Returns a ZIP archive containing one image per page.

HeaderValue
Content-Typeapplication/zip
Content-Dispositionattachment; filename="document_pages.zip"