PDF to Image API Endpoint

Version 2.197 (Release Notes ↗)

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-data
  • application/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'
    )
← Return to API Endpoint Listing