cURL Examples
Example cURL commands for PDF API.
cURL Examples
cURL is perfect for testing the API from the command line or scripting PDF generation.
Basic Markdown to PDF
curl -X POST https://api.renderpdf.dev/v1/pdf/markdown \
-H "Authorization: Bearer sk_live_your_key_here" \
-H "Content-Type: application/json" \
-d '{"markdown": "# Hello World\n\nThis is my first PDF!"}' \
--output hello.pdf
With Theme and Options
curl -X POST https://api.renderpdf.dev/v1/pdf/markdown \
-H "Authorization: Bearer sk_live_your_key_here" \
-H "Content-Type: application/json" \
-d '{
"markdown": "# Monthly Report\n\n## Summary\n\n- Revenue: $45,678\n- Users: 1,234",
"theme": "corporate",
"options": {
"format": "A4",
"margin": {
"top": "25mm",
"bottom": "25mm",
"left": "20mm",
"right": "20mm"
}
}
}' \
--output report.pdf
HTML to PDF
curl -X POST https://api.renderpdf.dev/v1/pdf/html \
-H "Authorization: Bearer sk_live_your_key_here" \
-H "Content-Type: application/json" \
-d '{
"html": "<!DOCTYPE html><html><head><style>body { font-family: Arial; padding: 40px; } h1 { color: #2563eb; }</style></head><body><h1>Invoice #1234</h1><p>Thank you for your business!</p></body></html>",
"options": {
"format": "A4",
"print_background": true
}
}' \
--output invoice.pdf
URL to PDF
curl -X POST https://api.renderpdf.dev/v1/pdf/url \
-H "Authorization: Bearer sk_live_your_key_here" \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com",
"options": {
"format": "A4",
"wait_for": 2000,
"full_page": true
}
}' \
--output webpage.pdf
Template to PDF
Coming Soon - This endpoint is not yet available.
curl -X POST https://api.renderpdf.dev/v1/pdf/template \
-H "Authorization: Bearer sk_live_your_key_here" \
-H "Content-Type: application/json" \
-d '{
"template": "invoice",
"data": {
"invoice_number": "INV-2025-001",
"date": "2025-01-18",
"customer": {
"name": "Acme Corp",
"email": "billing@acme.com"
},
"items": [
{"description": "Widget Pro", "quantity": 2, "unit_price": 29.99}
],
"total": 59.98
}
}' \
--output invoice.pdf
Using Environment Variables
Store your API key in an environment variable:
export PDFAPI_KEY="sk_live_your_key_here"
curl -X POST https://api.renderpdf.dev/v1/pdf/markdown \
-H "Authorization: Bearer $PDFAPI_KEY" \
-H "Content-Type: application/json" \
-d '{"markdown": "# Hello World"}' \
--output hello.pdf
PDF with Compression
Generate a PDF with compression enabled:
curl -X POST https://api.pdfapi.dev/v1/pdf/markdown \
-H "Authorization: Bearer $PDFAPI_KEY" \
-H "Content-Type: application/json" \
-d '{
"markdown": "# Large Document\n\nThis document contains lots of content...",
"options": {
"format": "A4",
"compression": {
"enabled": true,
"level": "medium"
}
}
}' \
--output compressed.pdf
PDF with Storage
Generate a PDF and store it for later retrieval:
curl -X POST https://api.pdfapi.dev/v1/pdf/markdown \
-H "Authorization: Bearer $PDFAPI_KEY" \
-H "Content-Type: application/json" \
-d '{
"markdown": "# Stored Document\n\nThis PDF will be stored for later access.",
"storage": {
"enabled": true,
"filename": "my-document.pdf"
}
}' \
--output document.pdf -v 2>&1 | grep "X-File-ID"
Merge Multiple PDFs
Combine multiple PDFs into one:
# First, encode your PDFs as base64
PDF1_BASE64=$(base64 -w 0 document1.pdf)
PDF2_BASE64=$(base64 -w 0 document2.pdf)
# Merge them
curl -X POST https://api.pdfapi.dev/v1/pdf/merge \
-H "Authorization: Bearer $PDFAPI_KEY" \
-H "Content-Type: application/json" \
-d "{
\"pdfs\": [
{\"data\": \"$PDF1_BASE64\"},
{\"data\": \"$PDF2_BASE64\"}
],
\"storage\": {
\"enabled\": true,
\"filename\": \"merged-documents.pdf\"
}
}" \
--output merged.pdf
Merge PDFs from URLs:
curl -X POST https://api.pdfapi.dev/v1/pdf/merge \
-H "Authorization: Bearer $PDFAPI_KEY" \
-H "Content-Type: application/json" \
-d '{
"pdfs": [
{"url": "https://example.com/cover.pdf"},
{"url": "https://example.com/content.pdf"},
{"url": "https://example.com/appendix.pdf"}
]
}' \
--output complete-report.pdf
Set PDF Metadata
Add metadata to a PDF:
PDF_BASE64=$(base64 -w 0 document.pdf)
curl -X POST https://api.pdfapi.dev/v1/pdf/metadata \
-H "Authorization: Bearer $PDFAPI_KEY" \
-H "Content-Type: application/json" \
-d "{
\"pdf\": \"$PDF_BASE64\",
\"metadata\": {
\"title\": \"Q4 2025 Financial Report\",
\"author\": \"Finance Department\",
\"subject\": \"Quarterly financial summary\",
\"keywords\": \"finance, quarterly, report, 2025\"
}
}" \
--output document-with-metadata.pdf
Get PDF Metadata
Retrieve metadata from a PDF:
# From a URL
curl -X POST https://api.pdfapi.dev/v1/pdf/metadata/get \
-H "Authorization: Bearer $PDFAPI_KEY" \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com/document.pdf"}' | jq
# From base64
PDF_BASE64=$(base64 -w 0 document.pdf)
curl -X POST https://api.pdfapi.dev/v1/pdf/metadata/get \
-H "Authorization: Bearer $PDFAPI_KEY" \
-H "Content-Type: application/json" \
-d "{\"pdf\": \"$PDF_BASE64\"}" | jq
List Stored Files
curl https://api.pdfapi.dev/v1/files \
-H "Authorization: Bearer $PDFAPI_KEY" | jq
Output:
{
"data": [
{
"id": "f47ac10b-58cc-4372-a567-0e02b2c3d479",
"filename": "report.pdf",
"size": 125430,
"created_at": "2025-01-20T10:30:00Z"
}
],
"pagination": {
"page": 1,
"total": 5
}
}
Download Stored File
FILE_ID="f47ac10b-58cc-4372-a567-0e02b2c3d479"
curl https://api.pdfapi.dev/v1/files/$FILE_ID/download \
-H "Authorization: Bearer $PDFAPI_KEY" \
--output downloaded.pdf
Delete Stored File
FILE_ID="f47ac10b-58cc-4372-a567-0e02b2c3d479"
curl -X DELETE https://api.pdfapi.dev/v1/files/$FILE_ID \
-H "Authorization: Bearer $PDFAPI_KEY"
Configure Webhook
Set up a webhook to receive notifications:
curl -X POST https://api.pdfapi.dev/v1/webhooks/config \
-H "Authorization: Bearer $PDFAPI_KEY" \
-H "Content-Type: application/json" \
-d '{
"url": "https://your-app.com/webhooks/pdfapi",
"events": ["pdf.generated", "pdf.failed"],
"secret": "your-webhook-secret"
}' | jq
Get Webhook Configuration
curl https://api.pdfapi.dev/v1/webhooks/config \
-H "Authorization: Bearer $PDFAPI_KEY" | jq
Delete Webhook Configuration
curl -X DELETE https://api.pdfapi.dev/v1/webhooks/config \
-H "Authorization: Bearer $PDFAPI_KEY"
Reading Markdown from File
# Create a markdown file
cat > document.md << 'EOF'
# Project Proposal
## Overview
This proposal outlines our plan for...
## Timeline
| Phase | Duration | Deliverables |
|-------|----------|--------------|
| Planning | 2 weeks | Requirements doc |
| Development | 6 weeks | Working prototype |
| Testing | 2 weeks | QA report |
## Budget
Total: $50,000
EOF
# Convert to PDF using jq to properly escape
curl -X POST https://api.renderpdf.dev/v1/pdf/markdown \
-H "Authorization: Bearer $PDFAPI_KEY" \
-H "Content-Type: application/json" \
-d "$(jq -n --rawfile md document.md '{markdown: $md, theme: "corporate"}')" \
--output proposal.pdf
Error Handling
Check the HTTP status code and parse error responses:
response=$(curl -s -w "\n%{http_code}" -X POST https://api.renderpdf.dev/v1/pdf/markdown \
-H "Authorization: Bearer $PDFAPI_KEY" \
-H "Content-Type: application/json" \
-d '{"markdown": ""}')
status_code=$(echo "$response" | tail -n1)
body=$(echo "$response" | sed '$d')
if [ "$status_code" -eq 200 ]; then
echo "$body" > document.pdf
echo "PDF saved successfully"
else
echo "Error: $body"
fi
Batch Processing
Process multiple files in a loop:
#!/bin/bash
for file in documents/*.md; do
filename=$(basename "$file" .md)
echo "Converting $file..."
curl -s -X POST https://api.renderpdf.dev/v1/pdf/markdown \
-H "Authorization: Bearer $PDFAPI_KEY" \
-H "Content-Type: application/json" \
-d "$(jq -n --rawfile md "$file" '{markdown: $md}')" \
--output "output/${filename}.pdf"
# Respect rate limits
sleep 1
done
Check Usage
curl https://api.renderpdf.dev/v1/usage \
-H "Authorization: Bearer $PDFAPI_KEY" | jq
Output:
{
"data": {
"plan": "pro",
"pdfs_generated": 156,
"pdfs_limit": 3000,
"pdfs_remaining": 2844
}
}
List API Keys
curl https://api.renderpdf.dev/v1/keys \
-H "Authorization: Bearer $PDFAPI_KEY" | jq
Tips
- Use
-sfor silent mode in scripts to suppress progress bars - Use
jqfor JSON parsing and construction - Respect rate limits with
sleepbetween requests - Store output as binary with
--outputflag - Check status codes for error handling
- Use
-w 0with base64 to avoid line breaks in encoded content