Forum Discussion
Creating a pdf file from Storyline running under an LMS
I know there are many excellent examples of how to create a pdf file in Storyline using javascript libraries such as jspdf and I have done this successfully in projects compiled for the web...
...but has anyone tackled this with an lms version? I know you could pass data to the lms using xAPI - but I really just want to click a button and "save" the pdf file created within the course using variables collected during the course.
Any ideas would be welcome.
47 Replies
- MarkWCommunity Member
Last question :)
Do either of you know how to use a web object to avoid having to edit the story.html file after publish? I saw a post about it a while back but didn't fully understand it.
- MarkWCommunity Member
Thanks for all of your answers, John. I really appreciate it.
- JohnCooper-be3cCommunity Member
Happy to help.
Having re-read you question - I guess I should also point out that my original error was not my code - but that I was trying to run the code above from a compiled version of my Storyline course on my local PC.
That won't work because the browser is complying with with the CORS (Cross Origin Resource Sharing) security protocol designed to prevent malicious files being loaded. Ironically, files on the same PC accessed via a file reference i.e. no "http: address" are not assumed to come from the same "origin" and therefore trigger a CORS error when the HTTP request to load the image (addImage) is executed.
When I moved the code and ran it on a server (I have my own cloud server but you could use Amazon or Microsoft Azure Cloud storage) the code runs fine because the file is accessed via it's http: address and the img.CrossOrigin ="": command basically tells the browser to accept an 'anonymous' unauthenticated image i.e. switch off the CORS check in the HTTP request.
Sorry that got a bit technical. In simple terms, you have to load the compiled web code with the image in the root folder onto a server for it to work - it won't work if you run it on your PC.
- MarkWCommunity Member
Thanks for the explanation, John. I've come accross a CORS error once or twice and wasn't sure what it meant. I've been using FTP for testing, as custom fonts seem to cause problems locally, too.
One more question, if I adapt the code you shared earlier and want to have different background images on each page of a multipage PDF, what would you suggest? I know how to generate new pages and suspect I would name images sequentially (page1.png, page2.png, etc.). Not quite sure of the other step, though...
- JohnCooper-be3cCommunity Member
Hi Mark
I haven't had the need to create multi-page pdf's yet but I see no problem in doing what you suggest. Just generate a new page and then use addimage.
Coincidentally, I submitted a proposal last week to a client that will require multi-page pdf's - so I may have to come to you to find out how to do it :)
I'm also looking at a more extensive javascript library pdf-lib which allows you to modify existing pdf files including filling out pdf forms. It looks really interesting. If I make progress with it I will create an article and publish it here.
- MarkWCommunity Member
I'm happy to help, though I suspect you're much more knowledgeable about all this.
And I'm curious to hear about your experience with the other javascript library. If it has the possibility to generate accessible PDFs, that would be especially appealing.
- JohnCooper-be3cCommunity Member
Just started work on a multi-page pdf document to be produced at the end of a course for my client. The requirement is that there are four screens in the course where the learner is asked to "reflect" on the section they have just covered and decide what they will do as a result.
Each of these screens has two questions - so there are 8 text responses which I have stored in variables in the course. At the end of the course, the learner will click a button to download a 4-page pdf. Each page has a summary of the section, the questions the learner was asked and their responses.
Code similar to that I published earlier works fine for the first page - the notes page is loaded as an image and the learner responses are positioned on the page to fill in the boxes.
I have added:
doc.addPage('landscape');
to the end of the first page and this successfully throws a pagebreak (there are actually two parametrs to this call - the page size is A4 by default but you can specify a different size as well as the orientation).
I will let you know how I get on...
- JohnCooper-be3cCommunity Member
OK - not trivial JavaScipt as it turns out - but I have solved it and can successfully produce a multi-page 'Notes' pdf document including the learner's own notes collected from text entry boxes through the course.
I will post a separate article on how to do this here on eLearning Heroes and post the link here when I have done it.
- JoaoCastroSilvaCommunity Member
Hey John. Reading through the comments was an emotional roller coaster. Please let me know when you post that article :) I'll be curious to learn from it.
- SarahlewisscottCommunity Member
Hey John! Did you ever get around to posting the article about a multi-page PDF? I successfully have a single page PDF download functionality with learner input and a background image, but I want to have a second page with a different background image and I haven't quite got the code right. Hoping to see yours as a model! Thanks!
- JohnCooper-be3cCommunity Member
Hi Joao
Thanks for the reminder about the article - I will definitely get to it. We have moved forward significantly and done several projects using this approach.
What we have done is develop code that:
A: retrieves the data from the variables in Storyline storing them in a table - one row per page.
B. we then add parameters to each variable in the table - font size, x and y pixel coordinates for the position on the page and the number of characters before we throw a new line
C. The code then processes the table in a loop reading the data associated with each variable creating a new page for each row according to the parameters.
It works fine - and we can produce complex handouts without having to modify the code - just by setting up the parameter table for each project.
All the best, John
- AriffKhalid-25fCommunity Member
Hi Matthew, Wondering if you could guide me.
i'm still getting the actionator::exeJavaScript - jsPDF is not defined error in console despite defining it in index_lms.html. I've also gone so far as to add it in story.html, index_lms.html, and also added a file href under imsmanifest.xml yet everytime i test it still gives me that error.
May i ask what other locations and changes you would need to make as you mentioned?thank you so much for your time
Related Content
- 2 months ago