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
- StephenPrice-83Community Member
I have been trying to add my own background but every time I put in the code or remove the logo code it ceases to download??
Any idea what I'm doing wrong?
- TeresaVanderposCommunity Member
Just wondering Ryan will your PDF example work if I don't have any questions, I just want a certificate if they completed the eLearning to the last slide? Do I have to do anything differently?
- LoganStahlerCommunity Member
Hi all-
First - Ryan, thanks so much! This is a great resource and your continued support for everyone is amazing. I am a bit new to the coding/java side of things so please excuse my newbie question. I can't, for the life of me, figure out how to modify the certificate image. We have a PDF version of a certificate that I am trying to make this work with, and I'm really struggling. I was able to copy your file (thank you!) into the project and it does generate the basic certificate as you intended. Now, I just need some direction in getting our PDF template as the background!
Any help from anyone would be amazing. We are on a tight deadline and I've been wracking my brain for hours now.
I am attaching our certificate for you all to see what we're looking to fill (simply name and date, that's it!)
Best,
Logan - RyanLowryCommunity Member
Hi Logan,
I've mocked up a quick example using the blank PDF certificate you supplied.
I exported the PDF as an image and converted it to a BASE64 string.
I then used this as the background for the certificate.
When you generate the certificate it should produce the attached PDF.
I've attached the source files for the certificate so you can give it a go.
Hope this helps!
Cheers,
Ryan
- LoganStahlerCommunity Member
Oh man, Ryan, this is sweet! THANK YOU! I will try it shortly, but one quick question - the date is off - 05/06/2018 - any idea why?
- RyanLowryCommunity Member
No worries! The date is in UK format DD/MM/YYYY e.g. 5th June 2018
You'll need to edit line 42 if you want to switch to another format e.g. MM/DD/YYYY
date = mm + '/' + dd + '/' + yyyy;
- LoganStahlerCommunity Member
Ahhh, that makes sense! Thanks again, looking forward to implementing this. You rock.
- LoganStahlerCommunity Member
Odd, I edited the certificate.html file with that line change and it's still spitting out 05/06/2018.
- RyanLowryCommunity Member
Did you delete and re-add the web object? You need to do this every time you make an edit.
- MichaelAmbechCommunity Member
For those of you who work in an international setting I have the following UTC time code running in my certificate.html:
// Get todays date in format dd/mm/yyyy
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth() + 1; //January is 0!
var yyyy = today.getFullYear();
if (dd < 10) {
dd = '0' + dd
}
if (mm < 10) {
mm = '0' + mm
}
date = today.toUTCString();And further down when defining the body of the document:
// Include date
{
text: '\n\n\n\n\nAwarded on: ' + date,
fontSize: 16,
alignment: 'center',
margin: [0, 0, 0, 0]
},
]
}; - TimHillierCommunity Member
Ryan/Ashley;
I tried to push the envelope with this today and have a question.
I published a storyline 360 to articulate online and put it into Rise as a Storyline block to see if I could get a certificate into Rise. It worked, kind of. It pulled default data for the variables rather than any input data. so it is getting something from the storyline file, it is just not updating the variables when I enter in a new name for example.
Any thoughts? I think this has great potential. Thank you for your work.
Tim
- RyanLowryCommunity Member
Tim Hillier
Ryan/Ashley;
I tried to push the envelope with this today and have a question.
I published a storyline 360 to articulate online and put it into Rise as a Storyline block to see if I could get a certificate into Rise. It worked, kind of. It pulled default data for the variables rather than any input data. so it is getting something from the storyline file, it is just not updating the variables when I enter in a new name for example.
Any thoughts? I think this has great potential. Thank you for your work.
Tim
Hi Tim,
Just did a quick test. Published to Articulate 360 and added as a Storyline block to Rise. All works as expected. Does your certificate generate properly when not added to a Rise project?
Cheers,
Ryan
Hey Tim,
Does the Storyline Block contain more than one slide? Does it have one slide for the learner to enter their name, and another slide to generate the certificate?
Also, are you using javascript to generate the certificate?
- TimHillierCommunity Member
Hey Alyssa;
It is just one slide with an entry box for the name and then the javascript discussed in this thread to generate the pdf certificate. The javascript seems to be using the default storyline variable values rather than accepting the input from the slide.
Tim
- TimHillierCommunity Member
Ryan;
I changed so many things trying to figure this out I was not sure where I left off. Thank you for the test and letting me know it can work. After realizing I had to go back and start over, I was able to get this to work with the changed logo and text perfectly.
This will be a wonderful addition to my rise courses that do not go into an LMS.
This is such a great service you have provided.
Thanks again.
Tim