Difference between revisions of "PDF Generation"
From SocialStack
(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...") |
|||
| Line 9: | Line 9: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
To use it, call | To use it, call createPdf which returns a promise. This is such that it can be [[Lazy loading|lazy loaded]] when necessary: | ||
<syntaxhighlight lang="js"> | <syntaxhighlight lang="js"> | ||
Revision as of 14:37, 31 August 2022
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 createPdf which 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.