Forum Discussion
Creating a pdf file from Storyline running under an LMS
Hi Mark
I haven't loaded jsPDF without modifying the story.html file - but that's because I don't use jsPDF anymore. I prefer to use the pdf-lib library which is more modern and more powerful (see discussion above). Because this library complies with the later ES6 module package format, you can actually load it dynamically FROM WITHIN THE JAVASCRIPT using an IMPORT statement:
async function loadMods() {
await import("https://unpkg.com/pdf-lib/dist/pdf-lib.js");
}
NOTE: This should really have some error handling in case it doesn't load,,, but that's straightforward.
Including this in the JavaScript code loads the library from (In this case) the unpkg.com repository at run time. I use an async function to call the 'import' statement so I can use 'await' which will ensure the library is loaded before progressing.
There were a few heroes who criticised this method of loading libraries - but it works fine for me - no noticeable delays. AND, a big plus, it works when using RISE - no messing around with the published code.
With regard to Michael's comment about the size of javaScript libraries, using the Import statement means I can selectively load just the methods I need eg:
import { PDFDocument } from 'https://unpkg.com/pdf-lib';
which means it loads even faster.
Regards