Images to PDF API
Turn JPEG or PNG images into a PDF, one image per page.
| Endpoint | POST https://astralpdf.com/api/v1/jpg-to-pdf |
| Auth | Bearer token, free |
| Sends | inputs: base64[] |
| Returns | result: base64 |
| Price | Free. 1,000 calls a day, 60 a minute. |
When to call it
Receipts, scans and photographed documents arrive as loose images and have to be filed as one document. Building the PDF in the step that receives them is what turns an inbox of photographs into something an accountant or an archive can accept.
For a one-off, the browser version needs no token and never sends your data anywhere: it runs on your own machine.
Example
curl
curl -X POST https://astralpdf.com/api/v1/jpg-to-pdf \
-H "Authorization: Bearer ast_YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{"inputs": ["/9j/4AAQSkZJRgABAQAA...","iVBORw0KGgoAAAANSUhEUg..."]}'response
{
"tool": "jpg-to-pdf",
"result": "JVBERi0xLjcKJWDjz9MKMSAwIG9iago8PC9UeXBlL0NhdGFsb2c...",
"chars": 9840,
"ms": 118
}In your language
JavaScript
const res = await fetch("https://astralpdf.com/api/v1/jpg-to-pdf", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.ASTRAL_TOKEN}`,
"Content-Type": "application/json",
},
body: JSON.stringify({"inputs": ["/9j/4AAQSkZJRgABAQAA...","iVBORw0KGgoAAAANSUhEUg..."]}),
});
if (!res.ok) throw new Error((await res.json()).detail);
const { result } = await res.json();Python
import os, requests
res = requests.post(
"https://astralpdf.com/api/v1/jpg-to-pdf",
headers={"Authorization": f"Bearer {os.environ['ASTRAL_TOKEN']}"},
json={"inputs": ["/9j/4AAQSkZJRgABAQAA...","iVBORw0KGgoAAAANSUhEUg..."]},
timeout=30,
)
res.raise_for_status()
result = res.json()["result"]Parameters
| Field | Type | Notes |
|---|---|---|
| inputs | string[] | Required. The file, base64 encoded. A data: URL is accepted too. Between 2 and 20 items. Up to 6,000,000 characters per call. |
Errors
Errors are RFC 7807 problem documents with a stable type you can branch on.
| missing-token | 401 | No Authorization header. |
| bad-request | 400 | inputs missing or the wrong type. |
| tool-failed | 422 | The input could not be processed. detail says why. |
| quota-exceeded | 429 | Past 1,000 calls today. |
Questions
- Which formats are accepted?
- JPEG and PNG. The format is detected from the bytes, so you do not have to say which is which, and anything else is refused with a clear message.
- How big is each page?
- Each page matches its image in pixels, so nothing is cropped, scaled or padded. Rescale first with the AstralBATCH resize endpoint if you want a fixed page size.
- How many images per call?
- Up to twenty, and their base64 counts together against the size limit. Split larger sets and merge the resulting PDFs.
Other endpoints
A token takes thirty seconds
Free, no card, 1,000 calls a day, and the same token works on astraltext.com, astralpdf.com, astraljson.com and astralbatch.com.
Get a free token