PDF Generation API Endpoint

Version 2.197 (Release Notes ↗)

Description

The PDF Generation API lets developers create invoices, reports, receipts, certificates, and other branded documents directly from code. Send Markdown, plain text, or HTML with images, links, and structured content, and PDFGEN will render the final PDF without requiring a separate PDF library in your stack. For bulk workflows, templates, and higher-level automation patterns, see the Rich PDF Generation page.

HTTP Methods

POST

HTTP Parameters

Fields Type Description
input String | Blob Raw document content to render into the generated PDF. Supported formats in this release are markdown, html, and plaintext.
format String | Format Format of the submitted input content. Supported values in this release are markdown, html, and plaintext.
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
blob Boolean By default, the API returns a JSON object with the generated PDF link. If set to true, the raw PDF binary is returned instead.

POST Request Body

Use this section when calling the endpoint with POST.

Allowed Content-Types:

  • multipart/form-data
  • application/json

HTTP Response

The endpoint returns application/json if the optional blob parameter is not set.

This endpoint returns a JSON object after each call unless the optional blob parameter is set to true. In the default mode, the response includes a link to the generated PDF stored in the AWS S3 bucket configured through the PixLab Console ↗. If blob=true, the generated PDF is returned directly. The JSON response includes the following fields:

Fields Type Description
status Integer Status code 200 indicates success. Any other code indicates failure.
link URL Link to the generated PDF document stored directly on your AWS S3 bucket, which you registered through the PixLab Console ↗.
id String Unique media identifier.
error String Error message when status ≠ 200.

Code Samples


# Programmatically Generate PDF document from markdown or HTML input
import requests
import json

# Replace with your actual PixLab API key
api_key = "YOUR_PIXLAB_API_KEY" # Get yours from https://console.pixlab.io/

# Markdown formatted invoice
markdown_text = """
# Invoice

## To:

Acme Corp.
123 Main St.
Anytown, USA

## From:

Your Company
456 Oak Ave.
Anytown, USA

## Date:

2024-01-26

## Invoice Number:

INV-2024-001

## Items:

| Item          | Quantity | Price    |
|---------------|----------|----------|
| Widget        | 2        | $10.00   |
| Gadget        | 1        | $25.00   |
| Service       | 1        | $50.00   |

## Subtotal:

$85.00

## Tax:

$5.00

## Total:

$90.00

## Notes:

Thank you for your business!
"""

# API endpoint to programmatically generate PDFs from markdown or HTML input
api_endpoint = "https://api.pixlab.io/pdfgen"

# Request parameters
payload = {
    "key": api_key,
    "input": markdown_text,
    "format": "markdown"
}

# Convert payload to JSON
headers = {'Content-Type': 'application/json'}

# Make the POST request
try:
    response = requests.post(api_endpoint, headers=headers, data=json.dumps(payload))

    # Check for successful response
    if response.status_code == 200:
        data = response.json()
        if data.get("status") == 200:
            pdf_link = data.get("link")
            print(f"PDF generated successfully.  Link: {pdf_link}")
        else:
            print(f"Error generating PDF: {data.get('error')}")
    else:
        print(f"Request failed with status code: {response.status_code}")
        print(response.text)  # Print the response content for debugging

except requests.exceptions.RequestException as e:
    print(f"An error occurred: {e}")
← Return to API Endpoint Listing