Forum Discussion
Javascript Certificate fail..!
HI Emily
Without blowing my own trumpet too loudly, I think the code you are using may be based on a post I put up a while back:
This post goes through the various stages of how to:
- Load the jspdf Javascript library
- Get the variables you need from the Storyline code
- Open your pdf file (in this case your certificate)
//Read pdf form
const { PDFDocument } = PDFLib;
const formUrl = 'https://articulateusercontent.com/review/uploads/pexRu_MmMKI4vlqomi0l677hphPje1Yv/U2GBcph3/assets/XXgil2/CertificateTemplate2.pdf';
const formPdfBytes = await fetch(formUrl).then (res => res.arrayBuffer());
const pdfDoc = await PDFDocument.load(formPdfBytes);
const form = pdfDoc.getForm();
- Extract the field names from your pdf file and store them in your JavaScript code
//Get field names
const nameField = form.getTextField('uName');
const dateField = form.getTextField('todaysDate');
- Assign your saved Storyline variables to the pdf file variables
- Create your new pdf file and save it
Having had a quick look at your code I can't see where you assign the saved Storyline variables to the saved form field variables.... i.e you need to fill the form in! So your code should have something like this in it:
//Fill in form
nameField.setText(learnerName);
dateField.setText(learnerDate);
var filename = learnerName + ".pdf"
I'm assuming that your certificate pdf has two fields in it called 'uName' and 'todaysDate' so that your '//Get field names' section of code works OK?
If you need more help - just shout and I can check it out for you...
Best regards
John
PS - I should add that this bug wouldn't explain why nothing happens when you click your button. The problem is that when Storyline runs the JavaScript code it doesn't pass the error message through to you. You need to open your browser debug tools to find what is going on....
I use Microspft Edge as my browser and F12 opens up the debug tools and if you look at the 'Console' tab you often find the error you are looking for...