Converting PDF Pages to High-Resolution Images
Conversion
Use Cases for PDF-to-Image Conversion
- Thumbnails — show a preview image in document management UIs
- Archiving — rasterise documents for long-term image-based archives
- Social sharing — generate a preview card from the first page
- OCR pipeline — convert to image before passing to an OCR engine
- Slide decks — export a PDF presentation as a sequence of images
API Usage
curl -X POST https://api.toolkitapi.io/v1/pdf/to-image \
-H "X-API-Key: $API_KEY" \
-F "[email protected]" \
-F "format=png" \
-F "dpi=150" \
-F "pages=1"
For a single page, the response is the image binary. For multiple pages, the response is a ZIP archive containing one image per page.
DPI Guidelines
| Use case | Recommended DPI |
|---|---|
| Web thumbnail | 72–96 |
| Screen preview | 120–150 |
| Print quality | 300 |
| High-res archiving | 600 |
Higher DPI = larger files. For web previews, 150 DPI at JPEG quality 85 is a good balance.
Format Choice
- PNG — lossless, best for text-heavy documents
- JPEG — smaller files, best for image-heavy pages
- WebP — smallest files, good for web delivery
Thumbnail Generation Pipeline
import httpx, zipfile, io
def generate_thumbnails(pdf_bytes: bytes, page_count: int) -> list[bytes]:
resp = httpx.post(
"https://api.toolkitapi.io/v1/pdf/to-image",
headers={"X-API-Key": API_KEY},
files={"file": pdf_bytes},
data={"format": "webp", "dpi": 96, "pages": f"1-{page_count}"},
timeout=30,
)
with zipfile.ZipFile(io.BytesIO(resp.content)) as zf:
return [zf.read(name) for name in sorted(zf.namelist())]