Forum Discussion
Storyline 2 Example - Generating a PDF Certificate for users who successfully complete a quiz
Hi all,
I've been experimenting with a JavaScript PDF library (pdfmake) to generate PDF certificates client side for learners who have successfully completed a quiz in Storyline 2.
You can see an example at http://rlowry.github.io/certificate/story.html
The 1st slide of the example provides a brief overview of how this works. I've tested this successfully in Internet Explorer, Chrome, Firefox, Chrome on Android and Safari on iOS.
I've attached a simple source file that contains a basic .story file as well as a folder (certificate) that includes the required HTML and JavaScript that needs to be included within a web object within the project. Feel free to have a look and re-use if it's useful.
The generated PDF certificate is very basic at the moment, you'll need to refer to the pdfmake documentation to update the design.
UPDATE: Originally this example only worked with the HTML5 output. I've tweaked it so it now works with the Flash output as well. I've updated the attached files to reflect this change.
UPDATE 2: I've updated the attached source files so they now use the latest version of pdfmake (v0.1.27).
Cheers,
Ryan
Hi Wes! Glad that you were able to find what you needed and that Ryan was able to assist as well.
I'm just popping in to mention that replying to the forums via e-mail attaches your signature. You are welcome to edit that if needed.
- wessykesCommunity Member
Thanks Leslie.
- NickyACommunity Member
Ryan just answered this a few posts up
- KevinBrake1Community Member
Hi Ryan,
My question to you is: How do you customize the background?
Specifically, can an existing PDF be imported into the background?
I would like to avoid using the online conversion tool, referred to in your previous posting.
This does not seem to work?
// under NodeJS (or in case you use virtual file system provided by pdfmake)
// you can also pass file names here
image: 'myImageDictionary/image1.jpg'Ideally with a vector based image would be great!
Thanks,
Kevin
- RyanLowryCommunity Member
Kevin Brake
Hi Ryan,
My question to you is: How do you customize the background?
Specifically, can an existing PDF be imported into the background?
I would like to avoid using the online conversion tool, referred to in your previous posting.
This does not seem to work?
// under NodeJS (or in case you use virtual file system provided by pdfmake)
// you can also pass file names here
image: 'myImageDictionary/image1.jpg'Ideally with a vector based image would be great!
Thanks,
Kevin
Hi Kevin,
As I mentioned in my previous post images must be converted to base64 strings and included as data uri's. You don't need to use an online converter, you can do this locally. I'm not going to go into how to do this, a quick google should point you in the right direction.
The following example demonstrates how you can use filenames when using pdfmake with NodeJS locally / on a server.
// under NodeJS (or in case you use virtual file system provided by pdfmake)
// you can also pass file names here
image: 'myImageDictionary/image1.jpg'There's no way to directly import a PDF, it would need to be converted to an image.
Unfortunately pdfmake doesn't support vector based images.
If you want to do something more advanced I think you'll have to do it server side. We use TCPDF to generate certificate PDF's server side with PHP in our VLE. This PHP class is much more advanced than pdfmake and the other javascript pdf libraries. Another benefit of generating server side is that you can keep a record of all issued certificate pdfs,
Cheers,
Ryan
- KevinBrake1Community Member
Thank you Ryan.
All the best,
Kevin
- janisstarsCommunity Member
Hi Ryan,
Would that be possible to get the storyine file "Certificate with Background Image" attached? :)
Thank you!
- RyanMartinCommunity Member
Nested iframes
Will the code still work?
If in an LMS, we have nested iframes. First iframe is for the lms <iframe class="tl-scorm-frame"... inside that we have the the web object...
Should this be updated to target the nested iframe:
var iframeElements = document.getElementsByTagName("iframe"); iframeElements[0].contentWindow.generatePDF();
If so, lil'help ;)
Late of night of google'n "nested iframe targeting" ...
/life of a gangster
Ryan
P.S. Great job Ryan
- RyanMartinCommunity Member
Maybe target the iframe id? If nested in an LMS?
<iframe frameborder="0" id="div5ZXigntYKK9.6C0CWw28H1t.64Y3LmijXhu.69J7dQoqcJI" src="..." style="border: 0px; width: 100%; height: 100%;"></iframe>
- RyanMartinCommunity Member
I'm going to Dev Learn like this...
- KarinFernandesCommunity Member
If there is more that one web object it is not possible to get the print certificate popup to appear. Is there a way around this?
- RyanLowryCommunity Member
It will be possible. You'll need to modify the JavaScript called by the Execute JavaScript trigger to target the specific webobject (iframe) that contains the certificate html. I'm on my phone at the moment so can't elaborate but I'll update this post tomorrow if nobody else has replied to you.
- KarinFernandesCommunity Member
Ryan thank you for your prompt reply. It works perfectly.
Hey Karin! So glad Ryan was able to step in here with a solution for you! We aren't equipped to support JavaScript work, but it feels good when the community can come up with good ideas.
- KarinFernandesCommunity Member
I seem to have broken the code! I can get the module to print in Firefox but not in IE or Chrome. I cannot see what has changed. I've attached a reduced version of the module.