Hello!
I am trying (and failing miserably and consistently!) to have Storyline create a downloadable PDF form filled by user input. I've searched through previous discussions, used some of that co...
You had an 'await' statement inside fillForm() but it was not declared as async. This code should work if you also fix the variable name (change it to PPDueDate in the variables panel) to avoid the "Error filling form."
// Retrieve Player Variables var player = GetPlayer(); var learnerRCGoal = player.GetVar("RCGoal"); var learnerRCDueDate = player.GetVar("RCDueDate"); var learnerRCActionPlan = player.GetVar("RCActionPlan"); var learnerPPGoal = player.GetVar("PPGoal"); var learnerPPDueDate = player.GetVar("PPDueDate"); var learnerPPActionPlan = player.GetVar("PPActionPlan"); var learnerSMSBGoal = player.GetVar("SMSBGoal"); var learnerSMSBDue = player.GetVar("SMSBDue"); var learnerSMSBActionPlan = player.GetVar("SMSBActionPlan"); var learnerRVGoal = player.GetVar("RVGoal"); var learnerRVDate = player.GetVar("RVDate"); var learnerRVActionPlan = player.GetVar("RVActionPlan");
// Construct PDF when player variables are retrieved ConstructPdf();
function ConstructPdf() { loadPdfLib(); // Load PDF-lib module and fill form }
async function fillForm() { // Read pdf form from URL const formUrl = 'https://sigep.org/wp-content/uploads/PhiGoals.pdf'; try { const formPdfBytes = await fetch(formUrl).then(res => res.arrayBuffer()); const pdfDoc = await PDFLib.PDFDocument.load(formPdfBytes); const form = pdfDoc.getForm();
// Get field objects from the form const RCGoalField = form.getTextField('RCGoal'); const RCDueDateField = form.getTextField('RCDueDate'); const RCActionPlanField = form.getTextField('RCActionPlan');
// Set text values in the form fields RCGoalField.setText(learnerRCGoal); RCDueDateField.setText(learnerRCDueDate); RCActionPlanField.setText(learnerRCActionPlan);