HTML to PDF API for invoices and reports
Send an HTML file and get a PDF back. Paper size and margins are set in the same request.
# API key: switchfile.io/dashboard/keys code=$(curl -sL "https://api.switchfile.io/v1/convert?wait=30" \ -o reply -D headers -w "%{http_code}" \ -H "Authorization: Bearer $SWITCHFILE_API_KEY" \ -H "Accept: application/octet-stream" \ -F 'options={"page_format":"a4","margin":"15mm"}' \ -F file=@invoice.html -F to=pdf) if grep -qi '^x-incomplete' headers; then grep -i '^x-notes' headers # partial result, left in reply elif [ "$code" = 200 ] && grep -qi '^content-disposition' headers; then mv reply invoice.pdf else # 202: still running, fetch links.self. Several files: result.files. cat reply # otherwise the error fi
// npm i switchfile import Switchfile from "switchfile"; const switchfile = new Switchfile({ apiKey: process.env.SWITCHFILE_API_KEY }); const conversion = await switchfile.convert("invoice.html", "pdf", { options: { page_format: "a4", margin: "15mm" }, }); await switchfile.download(conversion, "invoice.pdf");
# pip install switchfile-sdk import os import switchfile switchfile.configure(api_key=os.environ["SWITCHFILE_API_KEY"]) conversion = switchfile.convert("invoice.html", "pdf", {"page_format": "a4", "margin": "15mm"}) switchfile.download(conversion, "invoice.pdf")
<?php // composer require switchfile/switchfile-php require "vendor/autoload.php"; $switchfile = new Switchfile\Switchfile(["api_key" => getenv("SWITCHFILE_API_KEY")]); $conversion = $switchfile->convert("invoice.html", "pdf", ["page_format" => "a4", "margin" => "15mm"]); $switchfile->download($conversion, "invoice.pdf");
What comes back
With Accept: application/octet-stream, as in the curl example, a 200 response is the file itself when the conversion has exactly one result file. With several result files, for example one image per page, or without that header, you get the conversion as JSON, and the files are in result.files:
{
"id": "0b8a7c1e-5d0f-4a51-9f39-2f7f4c1d9a10",
"object": "conversion",
"status": "finished",
"progress": 100,
"input": {
"filename": "invoice.html",
"format": "html",
"size": 48213
},
"to": "pdf",
"options": {
"page_format": "a4",
"margin": "15mm"
},
"result": {
"files": [
{
"filename": "invoice.pdf",
"size": 61544,
"url": "https://api.switchfile.io/files/2a6f8e1c-4b3d-4e7a-9c5f-8d1b0e2a4c67/invoice.pdf?expires=1794074402&signature=3f9c2a7d41e8b6c05d1f9e2a7b4c8d3e6f0a1b2c3d4e5f60718293a4b5c6d7e8"
}
],
"incomplete": false
},
"download_url": "https://api.switchfile.io/files/2a6f8e1c-4b3d-4e7a-9c5f-8d1b0e2a4c67/invoice.pdf?expires=1794074402&signature=3f9c2a7d41e8b6c05d1f9e2a7b4c8d3e6f0a1b2c3d4e5f60718293a4b5c6d7e8",
"error": null,
"credits": 1,
"batch_id": null,
"created_at": "2026-11-06T18:00:00+00:00",
"finished_at": "2026-11-06T18:00:02+00:00",
"expires_at": "2026-11-07T18:00:02+00:00",
"links": {
"self": "https://api.switchfile.io/v1/conversions/0b8a7c1e-5d0f-4a51-9f39-2f7f4c1d9a10"
}
}What you get
Paper and margins
Styles from the file
Nothing loaded from outside
Markdown too
Options
Send them in options as JSON. Options that do not fit the format are rejected with a message that names them.
| Option | Meaning |
|---|---|
| page_ | Paper size. Without a value A4 is used unless the page sets its own size. |
| landscapelandscape | Landscape orientation. Default: false. |
| marginmargin | Page margin, for example 15mm, 1in or 20px. |
| print_ | Print background colors and images. Default: true. |
Where your files go
Converted on our server
Without storage: store=false
Data processing agreement
code=$(curl -s "https://api.switchfile.io/v1/convert?store=false" \
-o reply -D headers -w "%{http_code}" \
-H "Authorization: Bearer $SWITCHFILE_API_KEY" \
-F file=@invoice.html -F to=pdf)
if grep -qi '^x-incomplete' headers; then
grep -i '^x-notes' headers # partial result, left in reply
elif [ "$code" = 200 ] && grep -qi '^content-disposition' headers; then
mv reply invoice.pdf
else
cat reply # otherwise the error
fiPricing
Free
20
free API key
Credit pack
ā¬7
500 credits, one-time, no subscription
Monthly
ā¬4
500 credits a month, cancel at any time
HTML to PDF: 1 credit per started minute of conversion time, at least 1 per file.
A file that is done within a minute uses 1 credit, which costs ā¬0.0043 to ā¬0.014 depending on the plan or pack.
Add ?dry_run=1 to a convert request to see the credits and the price of a file before you convert it. Cost before converting
See all pricesSDKs and integrations
Questions
About HTML to PDF through the API.
What are the limits?
Files can be up to 1 GB. A file sent in the request can be up to 100 MB; larger files go through an upload, which the SDKs do on their own. One conversion can run for up to 5 minutes. Without storage (store=false), files can be up to 50 MB.
Does JavaScript run?
No. Scripts are not executed, so content that only appears through JavaScript is missing in the PDF. Send HTML that already contains the content.
Are images and stylesheets from the web loaded?
No. Only the file in the request is used, and external files are not fetched. Styles inside the HTML and images embedded as data URLs are included.
Which paper size is used by default?
A4, unless the page sets its own size in its CSS. Set page_format to choose another size, and landscape to turn the page.
What if my HTML needs JavaScript or images from the web?
Send it as html to the URL to PDF API. There JavaScript runs, and images and fonts load from public https addresses. Each capture costs 1 credit.
How long do you keep my files?
A stored conversion keeps the file and the result for 24 hours, then both are deleted. With store=false no file is stored: the result comes back in the response, and only an entry with time, formats, sizes and credits stays in your usage history for 400 days.