Convert Images to PDF
Learn how to convert multiple images into a single PDF file.
In many business workflows, you may need to convert multiple images, such as scans of a multi-page document, into a single, easy-to-share PDF file. The Scan Documents API makes this process simple and efficient.
Business Problem
Imagine you are working in an administrative role and need to compile a report from various scanned pages, which are currently saved as individual image files (e.g., JPEG, PNG). You need to combine these images into a single PDF document to ensure the pages are in the correct order and the file is easy to share and archive.
Solution
We can solve this problem by using the Scan Documents API to render multiple images into a single PDF. Here’s how:
- Upload the Images: First, you need to upload each image file to the Scan Documents API.
- Merge into PDF: Then, you'll use the
merge
operation to combine the uploaded images into a single PDF file.
Let's get started!
Step 1: Upload the Images
First, you need to upload each image file to the Scan Documents API. You will need to do this for each image you want to include in the PDF.
Upload a File
Creates a new file
# Upload the first image
curl -X POST "https://api.scan-documents.com/v1/files" \
-H "x-api-key: YOUR_API_KEY" \
-F name="Page 1" \
-F file="@/path/to/your/page1.jpg"
It will respond with a file object:
{
"id": "file_abc123",
"name": "Page 1",
"type": "image/jpeg",
"properties": {
"size": 50000,
"width": 800,
"height": 1200
},
"task_id": null,
"created_at": "2025-08-23T10:00:00.000Z"
}
# Upload the second image
curl -X POST "https://api.scan-documents.com/v1/files" \
-H "x-api-key: YOUR_API_KEY" \
-F name="Page 2" \
-F file="@/path/to/your/page2.jpg"
It will respond with a file object:
{
"id": "file_def456",
"name": "Page 2",
"type": "image/jpeg",
"properties": {
"size": 55000,
"width": 800,
"height": 1200
},
"task_id": null,
"created_at": "2025-08-23T10:01:00.000Z"
}
Take note of the id
from each response, as you'll need them in the next step.
Step 2: Merge Images into a PDF
Now that you have uploaded all your images, you can use the merge
operation to combine them into a single PDF. You will need to provide the file IDs of the images in the order you want them to appear in the PDF.
Merge files
Creates a task to merge multiple files (images or PDFs) into a single PDF document.
curl -X POST "https://api.scan-documents.com/v1/pdf-operations/merge" \
-H "x-api-key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "My Document.pdf",
"input": [
"file_abc123",
"file_def456"
]
}'
The result of this task will be a new PDF file containing your images.
{
"id": "task_ghi789",
"operation": "merge",
"status": "completed",
"parameters": {
"name": "My Document.pdf",
"input": [
"file_abc123",
"file_def456"
]
},
"result": {
"generated_files": [
{
"id": "file_jkl012",
"name": "My Document.pdf",
"type": "application/pdf",
"properties": {
"size": 102400,
"page_count": 2
},
"task_id": "task_ghi789",
"created_at": "2025-08-23T10:05:00.000Z"
}
]
},
"callback_url": null,
"created_at": "2025-08-23T10:04:00.000Z",
"updated_at": "2025-08-23T10:05:00.000Z"
}
And that's it! You can now download the generated PDF file using the /v1/files/{id}/download
endpoint. This single PDF file is now ready for sharing or archiving, with all pages in the correct order.