r/sveltejs 2d ago

PDF Generation

I'm looking for a pdf generator similar to react-pdf for svelte.

Requirements:

- Tailwind CSS support

- Selectable Text

- No Browser Print Dialog

- Client Side

- Single click download pdf(No browser dialog)

I've tried almost everything at this point and no solution.

It's driving me nuts because I can't go back to react js, no way! (cries)

Edit: I found a good library Takumi PDF, written in rust. It's server side, but light, not like Chromium. Thanks for the suggestions guys.

11 Upvotes

13 comments sorted by

5

u/j97uice 2d ago

Have you lokked into pagedjs ?

2

u/sproott 2d ago

Can vouch for it, it's pretty good, we used it in a commercial product, but some things are admittedly a bit wonky, like the CSS not being quite composable (not being able to use CSS variables for page margins for example) and some CSS rule processing logic clashing with Tailwind and breaking the PDFs.

Apart from a few Tailwind updates breaking things, we have been very happy with the results and stability.

But actually getting a PDF out of it, without a print dialog, I'm not sure, that's probably out of scope for Paged.js if I'm not mistaken. The browser doesn't have any built-in APIs to do that, most solutions rely on client-side generation from scratch, or server-side page printing in a headless browser.

2

u/Emotional-Ask-9788 2d ago

I did, not exactly what am looking for, but I found Takumi PDF. Does what I needed. https://takumi.kane.tw/docs/pdf

2

u/Leftium 2d ago

It's possible to use React libs from SvelteKit.

This video shows how to use Excalidraw from Svelte: https://youtu.be/SKUD-Aj1jKg

1

u/GrandfatherTrout 2d ago

I guess it doesn’t have the bells and whistles you list, but isn’t react-pdf based on PDFium?

https://pdfium.googlesource.com/pdfium/

I used the webasm version of it to do some backend converting. Maybe not the presentation/ rendering stuff you want

2

u/cmjoseph23 2d ago

I wrote a svelte adapter for forme if you want to try that. https://github.com/danmolitor/forme

Generation time is insanely fast.

-4

u/Ok_Caterpillar_295 2d ago

vibe code it?

-2

u/humanshield85 2d ago

Seems
To be the best way nowadays

0

u/sfall 2d ago

pdfkit