Storyline 360 - Generating a PDF Certificate using JavaScript
Jan 31, 2018
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)
90 Replies
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?
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!
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.
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.
Though I haven't used multiple fonts, the following links may be useful:
https://pdfmake.github.io/docs/fonts/custom-fonts-client-side/
https://github.com/bpampuch/pdfmake/issues/673
I think you have to update"pdfmake.js" as well. Make sure to include this in index.html file as the "pdfmake.min.js" is called in the default file.
Thank you I have played around with these but have not had luck yet ;0( I was trying to do this without installing gulp etc., others seem to have had success, but I have not had luck yet with those methods. I might have to install gulp and go that direction.
Hello, I may just try to go with only one font. I am trying to swap out Helvetica for Roboto. Did you create base 64 versions of the font for the vfs fonts.js file and replace the Roboto ones that were there? Thx.
Yes, I just converted the font to base64 using https://www.base64encode.org/enc/font/, and replaced the Roboto values in between " " in vfs_fonts.js file. If you want the bold and italic fonts, you can do the same or if you need only the regular style, you can just remove them from the vfs_fonts. js file (Roboto-italic, Roboto-medium and Roboto medium italic)
Thank you for responding, I tried and got some errors with bootstrap, I will have to try again later and see if I can get it to work. I did edit the vfs_fonts.js file, pdfmake.js files, I believe I have to do the .min file as well?
If you do any change on pdfmake.js file, instead of the min file include pdfmake in the index file.
" <script src='pdfmake/pdfmake.js'></script>"
If you require any help, you may send the font file to my e-mail, I will try with it.
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.
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 :)
That just means you have a bug in your code somewhere.
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
Very useful - but the documentation is rubbish!
Hi - I can't access the source files in the orginal post - can someone help me? thanks!
Hi - i can't download the source files - can anyone share them with me?
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.
Hi Kate - I've attached the source files to the original post.
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..
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.
LEGITIMATE hero!
I wondered if anyone could give me direction on how to edit the "lorem ipsum" text on the certificate?
Hey Jessika. That text is part of the SVG background image used in the example. You'll find this included inline within certificate.js on line 45 as shown below. This isn't easily editable. Instead you'll probably want to specify your own background image.
You can find more about including SVGs in the pdfmake docs - https://pdfmake.github.io/docs/0.1/document-definition-object/svgs/
Alternatively you could insert a jpeg of your own design - here: https://pdfmake.github.io/docs/0.1/document-definition-object/images/
i am SO super delighted that i've managed to ALMOST create a certificate. HOWEVER, I can't for the life of me work out how to get the variables in.
I have spent 3 hours on it and i'm going nuts.
also - not sure how everyone else gets their code in that fancy grey box......