PDF Generation
From SocialStack
Revision as of 14:36, 31 August 2022 by Luke (talk | contribs) (Created page with "Currently SocialStack has an installable module for generating PDFs on the frontend which is just a very thin wrapper for https://github.com/parallax/jsPDF jsPDF. It is su...")
Currently SocialStack has an installable module for generating PDFs on the frontend which is just a very thin wrapper for [jsPDF]. It is suitable for use in app projects as well as offline ones, and introduces minimal bloat to your site/ its load time.
Getting Started
First, install the module in to your project:
socialstack i UI/Functions/JsPdf
To use it, call createPdfwhich returns a promise. This is such that it can be lazy loaded when necessary:
import {createPdf} from 'UI/Functions/JsPdf';
...
// When you would like to start building a pdf:
createPdf({
orientation: "landscape",
unit: "in",
format: [4, 2]
}).then(doc => {
doc.text("Hello world!", 10, 10);
doc.save("a4.pdf");
})
createPdf will simply pass the object you give it to the [jsPDF constructor]. The response is the jsPDF object.