Generate a PDF with pdfmake (from SvelteKit)
ฝัง
- เผยแพร่เมื่อ 11 ก.ค. 2024
- SvelteKit Playlist: • SvelteKit 1.0 with SQL...
Code: github.com/phartenfeller/svel...
Demo: sveltekit-demo.hartenfeller.dev/
This time we will use the "pdfmake" NPM module to generate a PDF of a pages content on the server. The PDF includes different styles, a table, an image, a list and links.
Follow me:
Twitter: / phartenfeller
Mastodon: mastodon.social/@phartenfeller
Blog: hartenfeller.dev/blog
LinkedIn: / phartenfeller
Support me:
www.buymeacoffee.com/hartenfe...
paypal.me/phartenfeller
Timestamps:
0:00 Intro
02:39 Install needed modules
03:21 Add link to PDF download
04:07 PDF API Endpoint
06:03 Integrate Fonts for PDF
07:50 Hello World PDF
13:50 Add Styles
16:12 Add Table
19:25 Add Image
22:42 Add unordered list with links
Resources:
www.npmjs.com/package/pdfmake
pdfmake.org/playground.html
fonts.google.com/
PDF icons created by kliwir art - Flaticon : www.flaticon.com/free-icons/pdf - วิทยาศาสตร์และเทคโนโลยี
I had a bug where the font files are not included in the build. I fixed this by explicitly providing these assets to the container. See this commit where I resolved the issue: github.com/phartenfeller/sveltekit-1.0-sqlite-demo-app/commit/15e3c11ec6e198df6269a43d61d8fdbaeaf5b7ea
Thank you... so much
Thank you very much for answering this question of mine. I was thinking about the possibility of creating an API with nodejs. You saved me!
thank you for making this unique tutorial, go forward
Great video ❤. Really helpful
Hi! Thanks for the video and great explanation. I'm trying to generate the pdf following the steps mentioned, but the pdf stays loading and doesn't finish. From the logs on the server it seems that the pdf is being generated, but when it tries to consume from the client, stays loading. Do you know how to solve this? Thanks in advance!
hai can you give me example to generate pdfmake from database / mysql
with svg?
cant get this to work in production, on vercel, keep getting " ENOENT: no such file or directory, open 'src/lib/server/fonts/Roboto-Bold.ttf'" even though i have them in my directory
Hello, I tried to use with Node Adapter, but in production it fails because of __dirname in a dependency module (fontkit)
Sorry for the late reply but I had a bug all along that I finally noticed and fixed. The font files are not included in the build so I had to explicitly provide them: github.com/phartenfeller/sveltekit-1.0-sqlite-demo-app/commit/15e3c11ec6e198df6269a43d61d8fdbaeaf5b7ea
Have you gotten it to work on vercel? I'm running into the same issue
same issue@@henkbourgonje3344