简体   繁体   中英

jsPDF GetVar not working with a number variable

I'm using jsPDF in a Storyline 360 activity. I've been working with jsPDF and storyline for almost 2 years now, and we still use jsPDF version 1.5.3 since the newer version wouldn't work with our previously made courses.

I am having trouble getting a 'Number' variable to come into jsPDF. If the variable was instead a variable type 'Text' from storyline, it'll work fine though. It's just a number variable that breaks it. I've isolated it down to this issue, and included a code sample. I've started with a brand new storyline file, fresh variables, different variables names, the only thing that fixes it is changing my variable type to Text in storyline, which isn't a solution for me because I need to do math on these numbers in the activity, and bring those results to the generated PDF. Thank you for any guidance and help.

//Retrieve Player Variables
var player = GetPlayer();

userScore01 = player.GetVar("UserScore");

//Create PDF
var doc = new jsPDF();

doc.setFontType("bold");
doc.setFontSize(16);
doc.text(20, 28, userScore01);

//Save PDF
doc.save('Test.pdf');

I finally isolated this issue! It appears you cannot just display a numeric variable all by itself with doc.text, but need to instead add it to a text string or a text-based variable. So the following code updates worked:

doc.text(20, 28, userScore01 + ' points')

OR

doc.text(20, 28, userScore01 + userText) //where userText is a text-based variable

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM