Overview
The PDF is assembled with pdf-lib. Inputs arrive as multipart file parts (any field name, in form order), or as `image` (base64 data or a URL) followed by the URLs in `urls`. Each file is identified from its first bytes, not its name. URLs are downloaded with a 10 MB limit each and a 20-second timeout and must point to public hosts. More than 20 images, a file over 10 MB or 25 MB in total, or an unsupported format returns an error naming the problem, and no PDF is made.
JPEG and PNG images are embedded as they are: JPEG bytes are copied into the PDF unchanged and PNG pixels are stored losslessly. A JPEG whose EXIF orientation is not upright, and every HEIC, AVIF, WebP, BMP, GIF and TIFF image, is first decoded by APIVerve's image service (ImageMagick) and turned upright; photo formats come back as JPEG at quality 90 and the rest as PNG. Every frame of a GIF or TIFF becomes its own page, animated GIF frames composited as they display. When `quality` is set, every image goes through that step and is re-encoded as JPEG at that quality, with transparency flattened onto white.
With `pageSize` fit, each page measures the image at 96 pixels per inch (0.75 points per pixel) plus the margin on every side, capped at the 200-inch PDF limit. With a4 (595.28 x 841.89 pt), letter (612 x 792 pt) or legal (612 x 1008 pt), the image is scaled up or down to fit inside the margins, keeping its aspect ratio, and centred; orientation auto picks landscape when the image is wider than it is tall. `pageCount` can exceed `imageCount` because of multi-frame files. The Free plan stops at 5 pages and paid plans at 100; going over returns 403 or 400 before anything is stored.
Endpoint
One host, one path per API. The block below shows this call in four languages; every one of them is the same HTTP request. Making requests covers the timeouts, retries and parameter rules that apply to all of them. The SDKs wrap the same call in a typed client.
curl -X POST https://api.apiverve.com/v1/imagetopdf \
-H "x-api-key: your_api_key_here" \
-H "Content-Type: application/json" \
-d '{
"urls": [
"https://images.unsplash.com/photo-1507003211169-0a1dd7228f2d?w=1200",
"https://images.unsplash.com/photo-1449824913935-59a10b8d2000?w=1200"
],
"pageSize": "a4",
"orientation": "auto",
"margin": 10
}'const res = await fetch('https://api.apiverve.com/v1/imagetopdf', {
method: 'POST',
headers: {
'x-api-key': 'your_api_key_here',
'Content-Type': 'application/json',
},
body: JSON.stringify({
"urls": [
"https://images.unsplash.com/photo-1507003211169-0a1dd7228f2d?w=1200",
"https://images.unsplash.com/photo-1449824913935-59a10b8d2000?w=1200"
],
"pageSize": "a4",
"orientation": "auto",
"margin": 10
}),
});
if (!res.ok) throw new Error(`${res.status} ${await res.text()}`);
const { data } = await res.json();
console.log(data);import requests
res = requests.post(
"https://api.apiverve.com/v1/imagetopdf",
headers={"x-api-key": "your_api_key_here"},
json={
"urls": [
"https://images.unsplash.com/photo-1507003211169-0a1dd7228f2d?w=1200",
"https://images.unsplash.com/photo-1449824913935-59a10b8d2000?w=1200"
],
"pageSize": "a4",
"orientation": "auto",
"margin": 10
},
timeout=15,
)
res.raise_for_status()
print(res.json()["data"])package main
import (
"fmt"
"io"
"net/http"
"strings"
)
func main() {
body := strings.NewReader(`{
"urls": [
"https://images.unsplash.com/photo-1507003211169-0a1dd7228f2d?w=1200",
"https://images.unsplash.com/photo-1449824913935-59a10b8d2000?w=1200"
],
"pageSize": "a4",
"orientation": "auto",
"margin": 10
}`)
req, _ := http.NewRequest("POST", "https://api.apiverve.com/v1/imagetopdf", body)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("x-api-key", "your_api_key_here")
res, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer res.Body.Close()
out, _ := io.ReadAll(res.Body)
fmt.Println(string(out))
}Replace your_api_key_here with the key from your dashboard. When the inputs arrive as a list rather than one at a time, batch requests run up to 200 of them through this same API in a single call.
Authentication
Send your key in the x-api-key header. That is the only auth step — there is no token exchange and no per-endpoint scope to configure. Authentication covers creating, rotating and revoking keys.
A 401 means the key is missing, invalid or expired. A 403 means the key is valid but not permitted here — blocked by a key restriction or an IP allow-list. Running out of credits is a 429.
Parameters
Sent as JSON in the request body. Premium parameters are accepted on every plan but only take effect on plans that include them.
| Parameter | Type | Description |
|---|---|---|
imageOptional | string | An image file (upload one or more as multipart files, up to 20), base64 image data, or a public image URL |
urlsOptional | array | A JSON array of public image URLs, added in order after image. Up to 20 images per call in all |
pageSizeOptional | string | Page size: fit makes each page the size of its image; a4, letter and legal fit the image inside the marginsfita4letterlegaldefault a4 |
orientationOptional | string | Page orientation for a4, letter and legal; auto turns each page to match its image. Ignored for fitautoportraitlandscapedefault auto |
marginOptional | number | Margin around each image in millimetres, from 0 to 50 range 0–50 |
qualityOptional | integer | Re-compress every image as JPG at this quality (1-100) to make the PDF smaller. Omit to keep JPG and PNG images unchanged range 1–100 |
Response
Every API returns the same three top-level keys, so one response handler covers your whole integration: status, error and data. Only data changes shape. Response format covers the envelope, the other output formats and how premium fields are withheld.
{
"status": "ok",
"error": null,
"data": {
"pdfName": "7c1e4b9a-2f3d-4e8a-9b6c-5d0a1f2e3c4b.pdf",
"imageCount": 2,
"pageCount": 2,
"pageSize": "a4",
"orientation": "auto",
"margin": 10,
"quality": null,
"size": 483291,
"expires": 1792400000000,
"downloadURL": "https://storage.googleapis.com/apiverve/APIData/imagetopdf/7c1e4b9a-2f3d-4e8a-9b6c-5d0a1f2e3c4b.pdf?GoogleAccessId=635500398038-compute%40developer.gserviceaccount.com&Expires=1792400000&Signature=SAM…"
}
}
Response fields
Paths are relative to data. Premium fields are absent rather than zeroed on plans that do not include them, so check for presence instead of comparing to 0.
| Field | Type | Example | Description |
|---|---|---|---|
pdfName | string | "7c1e4b9a-2f3d-4e8a-9b6c-5d0a1f2e3c4b.pdf" | File name of the PDF |
imageCount | number | 2 | Number of images received |
pageCount | number | 2 | Pages in the PDF; more than imageCount when a GIF or TIFF has several frames |
pageSize | string | "a4" | Page size used |
orientation | string | "auto" | Orientation setting used; null for fit |
margin | number | 10 | Margin in millimetres |
quality | object | null | JPG quality images were re-compressed at, or null when they were kept unchanged |
size | number | 483291 | Size of the PDF in bytes |
expires | number | 1792400000000 | When the download link expires (Unix time in milliseconds) |
downloadURL | string | "https://storage.googleapis.com/apiverve/APIData/imagetopdf/7c1e4b9a-2f3d-4e8a-9b6c-5d0a1f2e3c4b.pdf?…" | Signed link to download the PDF, valid for 2 days |
Errors
Read the HTTP status first, then error for the specific reason. The body names the parameter that has to change. Error handling covers the full status list and which of them are worth retrying.
| Status | Meaning | What to do |
|---|---|---|
400 | Input was rejected | Read error; it names the parameter. |
401 | Key missing or invalid | Check the header name and the key value. |
403 | Key valid, but not permitted | A key restriction or IP allow-list; see key scoping. |
429 | Rate limited, or out of credits | Read error to tell them apart; see rate limits. |
Use cases
- Receipt and Expense Uploads
- Bundle photos of receipts taken on a phone into one PDF for an expense report or an accounting system.
- Scanned Document Packs
- Turn multi-page TIFF scans or a set of page photos into a single PDF that any viewer can open.
- Photo Books and Portfolios
- Assemble product shots or portfolio images into a PDF for clients, with consistent paper size and margins.
- Form Attachments
- Accept images in an upload form and store or forward them as one PDF, the format many back-office systems require.
Other ways to use Image to PDF
Set up Image to PDF on APIVerve, or reach the same source a different way. Your APIVerve account and credits work on all of them — one key, one balance.
Related
More in Documents: