Forum Discussion
Storyline 360 - Generating a PDF Certificate using JavaScript
This example demonstrates how to use the pdfmake JavaScript library to generate PDF certificates in the browser using Storyline 360.
This is a followup to my original post found here. The only changes from the original are that this is now a Storyline 360 project and pdfmake has been updated to the latest version (v0.2.4 at time of posting).
The linked 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.
The attached source files 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.
The generated PDF certificate is very basic at the moment, you'll need to refer to the pdfmake documentation to update the design.
Feel free to have a look and re-use if it's useful.
(21/03/2022 - pdfmake updated to v0.2.4 and example link replaced)
- PeterGallup-3a7Community Member
I'm not very savvy when it comes to javascript. How difficult would it be to add my companies logo and name to the PDF?
- JoannaLauCommunity Member
Hey Ryan, I've downloaded your source files, but I couldn't get it to publish a PDF. I didn't change anything except delete and re-add the web object to reflect it's new location on my local drive. Is there a way to get your file to work on my side?
- ChrisM-2d302595Community Member
In regards to this solution not working locally, it seems this solution only works when the web object is uploaded to a web server. To test, you can publish as LMS SCORM output, then upload to 'SCORM Cloud' (https://rusticisoftware.com/products/scorm-cloud/). Create a free login and it will allow you to upload your SCORM zip file. Then launch and it will work.
Refer to this reply from Ryan:
https://community.articulate.com/discussions/articulate-storyline/storyline-360-generating-a-pdf-certificate-using-javascript#reply-531709
- JeffForrerCommunity Member
Hello, has anyone had luck adding a font to pdfMake for the certificate? I have been struggling with this as Roboto is the default. I found the pdfMake documentation and many js articles on how to do so but can't get a font implemented. I have converted a fontset to base 64, tried adjusting the "vfs_fonts.js" file as well as creating a new class in the user.js file and referencing in my text fields but not having success. Thanks!
- SanduniFernandoCommunity Member
I have replaced the default Roboto font with my preferred font and it worked for me. Did you update the 'pdfmake.js' file as well?
Do you try to have multiple fonts in the PDF or just change the default font? I haven't had multiple fonts in "vfs_fonts.js" file but replacing the font worked for me.
- JeffForrerCommunity Member
Thanks, I did not try to replace it, I do have two fonts I need to use, so I added them to the vfs file. I know Roboto is listed as default in pdfmake.js, but I did not make a change there. Thank you for responding.
- JoshuaCooperDarCommunity Member
Thanks for info on using pdfmake as a web object!
I have everything working great except for custom fonts. When I try to add custom fonts to the HTML file. the PDF fails to print. I'm following all the instructions provided in pdfmake's github pages.I havent been able to find the cause of the bug but I ran across an old message board where JohnWemmick rand into a similar problem and said: "Found the problem. It was a problem with Articulate, not the pdfMake"
Is anyone familiar with this problem? Or do they have a working version with a custom font that I can use as a template?
I'm hoping to use brand fonts for the certificate instead of the default Roboto. - MaryGoemanRealoCommunity Member
Hello! When I edit the certificate.html using Atom or Code Writer - and then I delete and reinsert the web object the "download" button doesn't work upon republishing. Is there something I'm missing?
It will work fine and then I'll edit the html file, reinsert the web object and then nothing downloads.
I would appreciate any help :)
- JoshuaCooperDarCommunity Member
That just means you have a bug in your code somewhere.
- AdamBayliss-16aCommunity Member
Very useful - but the documentation is rubbish!
- KateMackenzieCommunity Member
Hi - I can't access the source files in the orginal post - can someone help me? thanks!
- KateMackenzieCommunity Member
Hi - i can't download the source files - can anyone share them with me?
- RyanLowryCommunity Member
Hi Kate - I've attached the source files to the original post.
- KateMackenzieCommunity Member
LEGITIMATE hero!
Hi Kate,
It looks like Ryan's files were not shared directly to the forums as an attachment, but on another website. You are welcome to reach out to the user directly via the 'Contact Me' option on the user profile if you do not hear back soon.
- AdamBayliss-16aCommunity Member
Hi all, nice to see this thread busy today! - I must admit I'm struggling with the Fonts - I found the instructions here: https://pdfmake.github.io/docs/0.1/fonts/custom-fonts-client-side/vfs/ but I'm not sure I understand.. "When you run command node build-vfs.js "./examples/fonts" in the pdfmake package directory.... How do I run command node build-vfs.js exactly? - Thanks for any advice..
- RyanLowryCommunity Member
Hi Adam, since this example was 1st developed PDFMake has received significant updates. It's now possible to link to font files by URL. See here - https://pdfmake.github.io/docs/0.1/fonts/custom-fonts-client-side/url/. I've updated the source files on my original post to include a version of PDFMake which should support this. I haven't tried it myself so not sure if / how well it works.