API Endpoint Access URL
https://api.pixlab.io/pdfgen
Get Your API Key & Try PDFGEN Now ↗Description
The PDF Generation API empowers you to create professional PDF documents, including invoices and complex documents, directly from your code. Utilizing markdown, plain text, or rich HTML with images, links, and structured content, you can generate PDFs dynamically and on-demand. This eliminates the need for external libraries, mitigating potential security risks. PDFGEN, our SDK-free REST API, provides a secure and efficient solution for all your PDF generation needs. For mass PDF generation, please refer to the Rich PDF Creation Page.
HTTP Methods
POST
HTTP Parameters
Fields | Type | Description |
---|---|---|
input |
String | Blob | Raw content in an appropriate format for parsing, rendering, and printing on the PDF document to be generated. Supported input formats as of this release are: markdown , html , or plaintext . |
format |
String | Format | format of the raw input contents. Supported input formats as of this release are: markdown , html , or 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, returns a JSON Object with the generated PDF document link. If true, returns the raw PDF binary instead. |
POST Request Body
Use when submitting a POST request instead of GET.
Allowed Content-Types:
multipart/form-data
application/json
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. The object contains a link to the generated PDF document stored directly on your AWS S3 bucket, which you registered through the PixLab Console ↗, but only if the optional blob
parameter is not set. If the blob
parameter is set to true
, the generated PDF document is returned directly. The JSON response body 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}")
// Programmatically Generate PDF document from markdown or HTML input
// Replace with your actual PixLab API key
const apiKey = "YOUR_PIXLAB_API_KEY"; // Get yours from https://console.pixlab.io/
// Markdown formatted invoice
const markdownText = `
# 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
const apiEndpoint = "https://api.pixlab.io/pdfgen";
// Request parameters
const payload = {
key: apiKey,
input: markdownText,
format: "markdown"
};
// Make the POST request
fetch(apiEndpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(payload)
})
.then(response => {
if (response.status === 200) {
return response.json();
} else {
console.error(`Request failed with status code: ${response.status}`);
return response.text().then(text => { throw new Error(text) }); // Throw error to be caught in catch block
}
})
.then(data => {
if (data.status === 200) {
const pdfLink = data.link;
console.log(`PDF generated successfully. Link: ${pdfLink}`);
} else {
console.error(`Error generating PDF: ${data.error}`);
}
})
.catch(error => {
console.error(`An error occurred: ${error}`);
});
<?php
# Programmatically Generate PDF document from markdown or HTML input
# 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 = <<<EOD
# 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!
EOD;
# API endpoint to programmatically generate PDFs from markdown or HTML input
$api_endpoint = "https://api.pixlab.io/pdfgen";
# Request parameters
$payload = array(
"key" =< $api_key,
"input" =< $markdown_text,
"format" =< "markdown"
);
# Initialize cURL
$ch = curl_init($api_endpoint);
# Set cURL options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
# Execute the cURL request
$response = curl_exec($ch);
# Check for errors
if (curl_errno($ch)) {
echo "Error: " . curl_error($ch);
} else {
# Get the HTTP status code
$http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($http_status == 200) {
$data = json_decode($response, true);
if ($data && $data["status"] == 200) {
$pdf_link = $data["link"];
echo "PDF generated successfully. Link: " . $pdf_link . "\n";
} else {
echo "Error generating PDF: " . ($data ? $data["error"] : "Unknown error");
}
} else {
echo "Request failed with status code: " . $http_status . "\n";
echo $response; // Print the response content for debugging
}
}
# Close cURL resource
curl_close($ch);
Similar API Endpoints
convert, tagimg, header, encrypt, llm-parse, copy, pdftoimg, llm-tools, query, bg-remove