Explore real-world scenarios and code examples for the most common PDF processing tasks.
Workflow IDs
All examples use placeholder workflow IDs. Use GET /api/v2/user/workflows to find the correct IDs for your account.
Convert multiple files in a single API call using async processing. Upload up to 50 files per request. When multiple files are processed with a convert workflow, the result is a ZIP archive containing individual PDFs.
# Upload multiple files at once
curl -X POST https://pdfen.com/api/v2/convert \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-F "files[]=@report1.docx" \
-F "files[]=@report2.docx" \
-F "files[]=@report3.docx" \
-F "workflow_id=1" \
-F "async=true"
<?php
$token = 'YOUR_API_TOKEN';
$files = ['report1.docx', 'report2.docx', 'report3.docx'];
// 1. Start async conversion
$postFields = ['workflow_id' => 1, 'async' => 'true'];
foreach ($files as $file) {
$postFields['files[]'] = new CURLFile($file);
}
$ch = curl_init('https://pdfen.com/api/v2/convert');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => ["Authorization: Bearer $token"],
CURLOPT_POSTFIELDS => $postFields,
]);
$result = json_decode(curl_exec($ch), true);
curl_close($ch);
$statusUrl = $result['status_url'];
// 2. Poll until done
do {
sleep(2);
$ch = curl_init($statusUrl);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ["Authorization: Bearer $token"],
]);
$status = json_decode(curl_exec($ch), true);
curl_close($ch);
} while ($status['status'] === 'processing' || $status['status'] === 'pending');
// 3. Download result (ZIP for multiple files, PDF for single file)
if ($status['status'] === 'done') {
$ch = curl_init($status['download_url']);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ["Authorization: Bearer $token"],
]);
file_put_contents('results.zip', curl_exec($ch));
curl_close($ch);
}
Add a searchable text layer to scanned PDFs. Use the options[ocr] and options[ocr_language] parameters to enable OCR.
curl -X POST https://pdfen.com/api/v2/convert \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-F "files[]=@scanned-document.pdf" \
-F "workflow_id=1" \
-F "options[ocr]=true" \
-F "options[ocr_language]=eng" \
-F "async=false"
<?php
$ch = curl_init('https://pdfen.com/api/v2/convert');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => ['Authorization: Bearer YOUR_API_TOKEN'],
CURLOPT_POSTFIELDS => [
'files[]' => new CURLFile('scanned-document.pdf'),
'workflow_id' => 1,
'options[ocr]' => 'true',
'options[ocr_language]' => 'eng',
'async' => 'false',
],
]);
$result = json_decode(curl_exec($ch), true);
curl_close($ch);
// Sync mode: download_url is immediately available
$ch = curl_init($result['download_url']);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['Authorization: Bearer YOUR_API_TOKEN'],
]);
file_put_contents('ocr-result.pdf', curl_exec($ch));
curl_close($ch);
eng (English), deu (German), nld (Dutch), fra (French), spa (Spanish), ita (Italian), por (Portuguese)
Reduce PDF file size using different compression levels. Use the "Compress PDF" workflow with the options[compression] parameter.
curl -X POST https://pdfen.com/api/v2/convert \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-F "files[]=@large-document.pdf" \
-F "workflow_id=1" \
-F "options[compression]=web" \
-F "async=false"
<?php
$ch = curl_init('https://pdfen.com/api/v2/convert');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => ['Authorization: Bearer YOUR_API_TOKEN'],
CURLOPT_POSTFIELDS => [
'files[]' => new CURLFile('large-document.pdf'),
'workflow_id' => 1,
'options[compression]' => 'web',
'async' => 'false',
],
]);
$result = json_decode(curl_exec($ch), true);
curl_close($ch);
echo "Original: " . filesize('large-document.pdf') . " bytes\n";
echo "Compressed: " . $result['output_file_size'] . " bytes\n";
web โ Optimized for screen viewing (good balance)print โ Optimized for printing (higher quality)small โ Maximum compression (smallest file size)none โ No compressionConvert email files (.eml, .msg) to PDF. Attachments are included in the converted output. Use the "Convert Email to PDF" workflow.
curl -X POST https://pdfen.com/api/v2/convert \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-F "files[]=@message.eml" \
-F "workflow_id=1" \
-F "async=false"
<?php
// Convert multiple email files at once
$ch = curl_init('https://pdfen.com/api/v2/convert');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => ['Authorization: Bearer YOUR_API_TOKEN'],
CURLOPT_POSTFIELDS => [
'files[0]' => new CURLFile('email1.eml'),
'files[1]' => new CURLFile('email2.msg'),
'workflow_id' => 1,
'async' => 'true',
],
]);
$result = json_decode(curl_exec($ch), true);
curl_close($ch);
echo "Execution ID: " . $result['execution_id'] . "\n";
echo "Poll status at: " . $result['status_url'] . "\n";
Supported formats: .eml (standard email), .msg (Outlook email). For PST archives, use the "Convert PST to PDF" workflow.
Merge multiple PDF files into a single document. Use the "Merge PDFs" workflow. You can control the order of files with the file_order parameter.
curl -X POST https://pdfen.com/api/v2/convert \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-F "files[]=@chapter1.pdf" \
-F "files[]=@chapter2.pdf" \
-F "files[]=@chapter3.pdf" \
-F "workflow_id=1" \
-F 'file_order=["chapter1.pdf","chapter2.pdf","chapter3.pdf"]' \
-F "async=false"
<?php
$ch = curl_init('https://pdfen.com/api/v2/convert');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => ['Authorization: Bearer YOUR_API_TOKEN'],
CURLOPT_POSTFIELDS => [
'files[0]' => new CURLFile('chapter1.pdf'),
'files[1]' => new CURLFile('chapter2.pdf'),
'files[2]' => new CURLFile('chapter3.pdf'),
'workflow_id' => 1,
'file_order' => json_encode(['chapter1.pdf', 'chapter2.pdf', 'chapter3.pdf']),
'async' => 'false',
],
]);
$result = json_decode(curl_exec($ch), true);
curl_close($ch);
// Download the merged PDF
$ch = curl_init($result['download_url']);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['Authorization: Bearer YOUR_API_TOKEN'],
]);
file_put_contents('merged.pdf', curl_exec($ch));
curl_close($ch);
You can also merge Word, Excel, or PowerPoint files into a single PDF. Use the appropriate merge workflow (e.g., "Merge Word to PDF") to convert and merge in one step.