API Endpoint Access URL
https://api.pixlab.io/pdftoimg
Get Your API Key & Try PDFTOIMG Now ↗Description
The PDF to image endpoint allows you to convert a PDF document into high-resolution JPEG or PNG images using a single, SDK-free REST API. This process converts one page at a time, ensuring optimal efficiency and image quality. For dynamic, on-demand generation of complex PDFs, such as invoices, from your programming environment using Markdown or HTML input, utilize the PDGGEN API endpoint.
HTTP Methods
GET, POST
HTTP Parameters
Fields | Type | Description |
---|---|---|
src |
URL | Input PDF URL. If you want to upload your PDF directly from your app, submit a multipart/form-data POST request. |
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 PDF page (index 0) is extracted. If the page number is out of range, the last page is converted. |
export |
String | Output image format (e.g., JPEG or PNG ). |
blob |
Boolean | By default, returns a JSON Object with the output image link. If true, returns the image binary directly. |
POST Request Body
Use when submitting a POST request instead of GET.
Allowed Content-Types:
multipart/form-data
application/json
Use multipart/form-data
for direct PDF uploads (see REST API code samples). For JSON, the PDF must be hosted elsewhere.
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, copy, pdfgen, llm-tools, query, bg-remove