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...") |
|||
| (One intermediate revision by the same user not shown) | |||
| Line 1: | Line 1: | ||
Currently SocialStack has an installable module for generating PDFs on the frontend which is just a very thin wrapper for | 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 suitable for use in app projects as well as offline ones, and introduces minimal bloat to your site/ its load time. | ||
= Getting Started = | = Getting Started = | ||
| 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"> | ||
| Line 28: | Line 28: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
createPdf will simply pass the object you give it to the | createPdf will simply pass the object you give it to the [https://github.com/parallax/jsPDF#usage jsPDF constructor]. The response is the jsPDF object. | ||
Latest 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.