API Endpoint Access URL
https://api.pixlab.io/pdftoimg
Get Your API Key & Try PDFTOIMG Now ↗Description
The PDF to Image API lets developers convert PDF pages into high-resolution JPEG or PNG output with a simple REST request. It is designed for page-by-page rendering, which makes it a good fit for preview generation, document pipelines, archival workflows, and apps that need image output from PDF content. If you need to generate PDFs from HTML, Markdown, or structured content, use the PDFGEN API endpoint.
HTTP Methods
GET, POST
HTTP Parameters
| Fields | Type | Description |
|---|---|---|
src |
URL | Source PDF URL. If you want to upload the file directly from your app or backend, send a multipart/form-data POST request instead. |
key |
String | Your PixLab API Key ↗. You can also embed your key in the WWW-Authenticate: HTTP header and omit this parameter. |
Optional
| Fields | Type | Description |
|---|---|---|
pagenumber |
Integer | Target page number to convert. If omitted, the first page (index 0) is used. If the requested page is out of range, the last page is returned. |
export |
String | Output image format, such as JPEG or PNG. |
blob |
Boolean | By default, the API returns a JSON object with the output image link. If set to true, the API returns the image binary directly. |
POST Request Body
Use this section when calling the endpoint with POST instead of GET.
Allowed Content-Types:
multipart/form-dataapplication/json
Use multipart/form-data when uploading a PDF file directly. Use JSON when the source PDF is already hosted and accessible by URL. See the REST API code samples for working request patterns.
HTTP Response
The endpoint returns application/json if the optional blob parameter is not set.
This API endpoint returns a JSON Object after each call only if the optional blob parameter is not set. Otherwise, the converted image is returned directly. The following fields are included in the JSON response body:
| Fields | Type | Description |
|---|---|---|
status |
Integer | Status code 200 indicates success. Any other code indicates failure. |
link |
URL | Link to the image output stored on our high-performance pixlab.xyz storage server. You can configure custom S3 storage (see your dashboard ↗ for setup instructions). |
id |
String | Unique media identifier. |
error |
String | Error message when status ≠ 200. |
Code Samples
import requests
from typing import Dict, Any
def convert_pdf_to_image(
pdf_url: str,
export_format: str = 'jpeg',
api_key: str = 'PIXLAB_API_KEY'
) -> None:
"""Convert a PDF document to JPEG/PNG image using PixLab API."""
try:
response = requests.get(
'https://api.pixlab.io/pdftoimg',
params={
'src': pdf_url,
'export': export_format,
'key': api_key
},
timeout=10
)
response.raise_for_status()
data: Dict[str, Any] = response.json()
if data.get('status') != 200:
print(f"Error: {data.get('error', 'Unknown error')}")
else:
print(f"Link to the image output: {data['link']}")
except requests.exceptions.RequestException as e:
print(f"Request failed: {e}")
except ValueError as e:
print(f"Invalid JSON response: {e}")
if __name__ == '__main__':
convert_pdf_to_image(
pdf_url='https://www.getharvest.com/downloads/Invoice_Template.pdf'
)
fetch('https://api.pixlab.io/pdftoimg?src=https://www.getharvest.com/downloads/Invoice_Template.pdf&export=jpeg&key=PIXLAB_API_KEY')
.then(response => response.json())
.then(reply => {
if (reply.status !== 200) {
console.log(reply.error);
} else {
console.log("Link to the image output (Converted PDF page): " + reply.link);
}
})
.catch(error => console.error('Error:', error));
<?php
$params = [
'src' => 'https://www.getharvest.com/downloads/Invoice_Template.pdf',
'export' => 'jpeg',
'key' => 'PIXLAB_API_KEY'
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.pixlab.io/pdftoimg?' . http_build_query($params));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
$response = curl_exec($ch);
if (curl_errno($ch)) {
die('Curl error: ' . curl_error($ch));
}
curl_close($ch);
$reply = json_decode($response, true);
if ($reply['status'] != 200) {
die($reply['error']);
} else {
echo "Link to the image output (Converted PDF page): " . $reply['link'];
}
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse('https://api.pixlab.io/pdftoimg')
params = {
'src' => 'https://www.getharvest.com/downloads/Invoice_Template.pdf',
'export' => 'jpeg',
'key' => 'PIXLAB_API_KEY'
}
uri.query = URI.encode_www_form(params)
response = Net::HTTP.get_response(uri)
reply = JSON.parse(response.body)
if reply['status'] != 200
puts reply['error']
else
puts "Link to the image output (Converted PDF page): #{reply['link']}"
end
Similar API Endpoints
convert, tagimg, header, encrypt, llm-parse, DOCSCAN, pdfgen, llm-tools, query, bg-remove