Our great sponsors
-
svg2pdf.js
A javascript-only SVG to PDF conversion utility that runs in the browser. Brought to you by yWorks - the diagramming experts
-
SurveyJS
Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App. With SurveyJS form UI libraries, you can build and style forms in a fully-integrated drag & drop form builder, render them in your JS app, and store form submission data in any backend, inc. PHP, ASP.NET Core, and Node.js.
If you decide to go with PDF, I highly suggest https://github.com/parallax/jsPDF
If you need to print to exact dimensions, you MUST use PDF. This was what i needed, so I draw everything to an SVG, and made sure that my units were in "pt" (that is 1px = 1/72inch). When creating the PDF, I specified that the units were in "pt" and used https://github.com/yWorks/svg2pdf.js/ to convert the SVG. Note that this has major disadvantages. SVG does not support word wrap by default; you'll have to write your own. You'll also have to get users to specify a paper size in your app. Again, test, test, test. If you want to preview the PDF, not all browsers can display PDF natively (looking at you Android)! Some browsers won't print exact size even in PDF (Android). Some browsers will reduce page margins if printing from an inline iframe preview (Safari). You need annoying workarounds. Like downloading instead of previewing the file on Android, or making sure to always open a new tab on Safari.
Recently, we had a requirement for it to be a PDF at my work, and the only good thing we found that could do it in javascript was react-pdf. It doesn't work exactly like react, and it sure ain't Svelte, but it is pretty friendly to create a pdf and relatively fast (generate 10-15 pages in around 2-3s for us, with lots of graphics and charts). And we managed to make it work backend side (in an aws lambda).