Svelte to PDF
Svelte to PDF With a SvelteKit PDF Generation API
Turn a Svelte component or a SvelteKit route into a real, selectable PDF from one fetch in a server endpoint. Managed Chromium lays out your markup, so scoped styles, Tailwind and web fonts print the way they look on screen, and no browser has to fit inside your adapter. Try it on any URL or HTML below.
- PDF and archive in one call
- Plans from $49 a month
- Your HTML stays yours
Live demo
Runs in your browser. Nothing is uploaded. One PDF free to try, then a plan.
Your HTML
Live preview
Your PDF is downloading. That was the free one. The Starter plan converts as many as you need, for $49 a month or $288 a year, half price.
See the planShort answer
The reliable way to go from Svelte to PDF is to render the component to HTML on the server and let a real browser print it. In SvelteKit that is a +server.ts endpoint: call render() from svelte/server, inline your CSS, POST the HTML to SitePDF and return the PDF. Text stays selectable, page breaks follow your print CSS, and it runs on serverless adapters where Chromium will not start. Plans start at $49 a month for 10,000 renders.
Written and fact checked by the SitePDF team.
Four ways to get a PDF out of a Svelte app
Svelte ships no PDF export, so every team ends up on one of these routes. They split on two questions: does the PDF contain real text, and can it be made without a person clicking a button.
| Approach | Where it runs | Output | Works on serverless adapters | Best for |
|---|---|---|---|---|
| window.print() with print CSS | The user's browser | True vector PDF, but the user picks paper, margins and headers in the dialog | Not applicable, nothing runs on the server | A one off printout a signed in user starts themselves |
| html2pdf.js or jsPDF in a component | The user's browser | html2pdf.js embeds a canvas image, jsPDF needs every element placed in code | Not applicable | A short receipt or label where image text is acceptable |
| Puppeteer or Playwright in a Node adapter | Your own server | True vector PDF | No, Chromium is too large for most function limits and cold starts hurt | Teams already running adapter-node on a long lived box |
| Rendering API from a +server.ts endpoint SitePDF |
Managed Chromium, called with fetch | True searchable vector PDF with headers, footers and page numbers | Yes, it is one HTTP request | Invoices, statements and reports sent from a workflow, with a dated copy kept |
The honest read: if your users only print what they see, window.print() plus a print stylesheet is free and produces real text, so start there. The API earns its fee when nobody is at the keyboard, for example an invoice emailed after a webhook, or when every customer must get the same paper size and footer.
Render the component to HTML inside a SvelteKit endpoint
Svelte 5 ships a server renderer in the box. render() from svelte/server takes a component and its props and returns body and head strings, which is everything a printer needs except your CSS. Put the call in a +server.ts file so it never runs in the browser and your API key stays on the server.
// src/routes/invoices/[id]/pdf/+server.ts
import { render } from "svelte/server";
import Invoice from "$lib/Invoice.svelte";
import invoiceCss from "$lib/invoice.css?inline";
import { SITEPDF_KEY } from "$env/static/private";
export async function GET({ params, locals }) {
const invoice = await locals.db.invoice(params.id);
const { body, head } = render(Invoice, { props: { invoice } });
const html = `<!doctype html><html><head>${head}<style>${invoiceCss}</style></head><body>${body}</body></html>`;
const res = await fetch("https://api.sitepdf.com/v1/render", {
method: "POST",
headers: { Authorization: `Bearer ${SITEPDF_KEY}` },
body: new URLSearchParams({ html, format: "Letter", archive: "true" }),
});
const { pdf_url } = await res.json();
return Response.redirect(pdf_url, 303);
}The detail that trips most people: component styles are compiled into your bundle, not into the string render() returns. Keep the document styles in one plain stylesheet and import it with ?inline, as above, or link an absolute stylesheet URL in the head. Fonts follow the same rule, so reference them by absolute URL. If a font still falls back, the checklist in why fonts do not load in HTML to PDF covers the usual causes.
Or point the renderer at a live route
If the invoice already exists as a page in your app, skip the string building. Send the route URL instead of html, and the renderer loads it like a visitor, runs your hydration, and prints it. Add wait_for with a selector that only appears once data has loaded, such as #invoice-total, so a chart or a lazy table is never captured half drawn. The guide to waiting for content before you convert explains when a selector beats a fixed delay. Protect the route with a signed, expiring token in the query string rather than your session cookie.
Both inputs hit the same endpoint, described on the URL to PDF API page. Teams moving between frameworks reuse the call unchanged, and the Vue to PDF and Next.js PDF generator pages show the same pattern for those stacks.
Why the browser-side libraries disappoint on invoices
The Svelte ecosystem has several small PDF packages, and most of them are viewers rather than generators. The generators that run in the browser mostly wrap html2pdf.js, which draws your component onto a canvas with html2canvas and drops that bitmap into a PDF. That is fine for a quick export of one screen. On an invoice it means the amounts cannot be selected or searched by the customer's accounting software, a long table of line items is cut wherever the image happens to end, and Tailwind v4 colors written with oklch() throw during capture.
The other common route is to install Puppeteer next to adapter-node. That works on a server you keep running, and it is free. It stops working the moment you switch to a serverless or edge adapter, because the Chromium binary is larger than typical function limits and edge runtimes cannot start a browser process at all. The Puppeteer alternative page compares what it takes to keep a browser pool healthy against handing that job to an API.
A worked example for a SvelteKit SaaS
Take a SvelteKit billing app on a serverless adapter that issues 3,000 invoices a month, each two pages built from about 20 KB of HTML, plus around 400 ad hoc statement exports by users. That is 3,400 renders a month, well inside the Starter API plan at $49 a month (or $288 billed yearly) for 10,000 renders with a 90 day archive. Each invoice call returns a link in about two seconds, so a month end batch sent eight at a time finishes in roughly 15 minutes.
The alternative is a separate always on container just to host Chromium for those 3,400 documents, plus the time to keep its fonts, sandbox flags and memory limits right. Our Playwright production cost breakdown puts numbers on that upkeep for a larger volume. Under 10,000 documents a month the API is usually the cheaper line on the budget, and you get a dated copy of every invoice you sent, which helps when a customer disputes what was on it.
Keep a dated copy of each document
Add archive=true and SitePDF stores a timestamped, unchanged copy of exactly what it rendered, retrievable later by document id. For a billing app that answers the question every support team eventually gets: what did the invoice say on the day we sent it. Plan limits and retention periods are on the pricing page, and the invoice PDF API guide goes deeper on numbering, totals and multi page line items.
curl https://api.sitepdf.com/v1/render \
-H "Authorization: Bearer $SITEPDF_KEY" \
-F url=https://app.example.com/invoices/8842?token=signed \
-F format=Letter \
-F wait_for="#invoice-total" \
-F archive=true
{
"pdf_url": "https://api.sitepdf.com/v1/documents/doc_9s2kd.pdf",
"pages": 2,
"rendered_in_ms": 1740
}
This is the documented API call shape. Full request and response walkthrough.
Questions about this job
How do I convert a Svelte component to PDF?
Can SvelteKit generate a PDF on Vercel or Netlify?
Why are my component styles missing from the PDF?
Is window.print() good enough for PDFs in Svelte?
Does it work with Svelte 4?
Index
More PDF and archiving tools
- Convert HTML to PDF
- Webpage to PDF
- URL to PDF API
- Website archiving
- Monitor website changes
- Screenshot API
- React to PDF
- Java PDF library
- C# PDF library
- Python PDF generation
- HTML to PDF Node.js
- Laravel HTML to PDF
- Vue to PDF
- Next.js PDF generator
- Angular to PDF
- Markdown to PDF API
- Django HTML to PDF
- Blazor HTML to PDF
- Spring Boot HTML to PDF
- Airtable to PDF
- Rotativa alternative
- Zapier and Make HTML to PDF
- Golang HTML to PDF
- Rails HTML to PDF
- PDF generator API
- Website archiving software
- Document generation API
- Legal document automation software
- Document automation software
- Bulk HTML to PDF
- Accessible PDF generation
- ADA compliance audit cost
- 508 compliance testing
- PDF remediation
- VPAT and ACR
- PDF accessibility checker
- Wayback Machine alternative
- Best HTML to PDF API
- DocRaptor alternative
- Puppeteer alternative
- Wkhtmltopdf alternative
- PDFShift pricing and alternative
- Urlbox pricing and alternative
- PDFCrowd alternative
- Api2Pdf alternative
- Browserless alternative
- APITemplate alternative
- CraftMyPDF alternative
- PDFMonkey alternative
- dompdf alternative
- WeasyPrint alternative
- jsPDF alternative
- mPDF alternative
- Website archiving pricing comparison
- HTML to PDF API for ecommerce
- HTML to PDF API for SaaS
- HTML to PDF API for accounting software
- PHP convert HTML to PDF
- PrinceXML alternative
- PDFreactor alternative
- PDF integrity check
- Invoice PDF archive
- PDF page numbers, headers and footers
- PDF of pages behind a login
- Website archiving for law firms
- React PDF renderer alternative
- Gotenberg alternative
- GrabzIt alternative
- Adobe PDF Services API
- PDF SDK pricing
- HTML to image API pricing
- Adobe Document Generation API pricing
- jsreport pricing
- PDFBolt pricing
- PDFEndpoint pricing
- Formstack Documents pricing
- Documint pricing
- iLovePDF API pricing
- Browserless pricing
- PandaDoc API pricing
- CloudConvert API pricing
- Encodian pricing
- IronPDF pricing
- Salesforce document generation pricing
- Winnovative pricing
- SelectPdf, HiQPdf and EvoPdf pricing
- CloudConvert alternative
- Direct mail API pricing
- E-signature API pricing
- Sparticuz Chromium Lambda cost
- Browserbase pricing
- Aspose PDF pricing
- PDF API pricing
- How it works
- Features
- Pricing
Get started
Render and archive with one API call
A pixel perfect PDF and a dated copy of the page from the same request. Plans from $49 a month, half price billed yearly.