最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Text not displaying calculated numbers in PDF where console logging correctly - Stack Overflow

programmeradmin4浏览0评论

I am using jsPDF in a Vue 2 project to generate a PDF report. The issue I’m facing is that my calculated numbers are not appearing in the generated PDF, even though they print correctly in the console.The data type of totalNumberOfLicense.USED and FREE are long(as per server side).

const totalBind = Number(this.totalNumberOfLicense.USED);
const totalAvailable = Number(this.totalNumberOfLicense.FREE);
const newLicenseIssued = totalAvailable + totalBind;


console.log("totalBind : ", totalBind);
console.log("Free: ", totalAvailable);
console.log("New License Issued: ", newLicenseIssued);

const licenseSummary = `Base License (New License Issued): ${newLicenseIssued},Total Bind: ${totalBind}, Total Available: ${totalAvailable}`;

doc.text(licenseSummary, leftMargin, imgY + imgHeight + 44);

Console output

totalBind :  536
Free:  13525
New License Issued:  14061

However, in the generated PDF, the text appears as:

Base License (New License Issued): , Total Bind: , Total Available: 

How to fix this issue ?

I am using jsPDF in a Vue 2 project to generate a PDF report. The issue I’m facing is that my calculated numbers are not appearing in the generated PDF, even though they print correctly in the console.The data type of totalNumberOfLicense.USED and FREE are long(as per server side).

const totalBind = Number(this.totalNumberOfLicense.USED);
const totalAvailable = Number(this.totalNumberOfLicense.FREE);
const newLicenseIssued = totalAvailable + totalBind;


console.log("totalBind : ", totalBind);
console.log("Free: ", totalAvailable);
console.log("New License Issued: ", newLicenseIssued);

const licenseSummary = `Base License (New License Issued): ${newLicenseIssued},Total Bind: ${totalBind}, Total Available: ${totalAvailable}`;

doc.text(licenseSummary, leftMargin, imgY + imgHeight + 44);

Console output

totalBind :  536
Free:  13525
New License Issued:  14061

However, in the generated PDF, the text appears as:

Base License (New License Issued): , Total Bind: , Total Available: 

How to fix this issue ?

Share Improve this question edited Mar 20 at 7:35 DarkBee 15.5k8 gold badges72 silver badges117 bronze badges asked Mar 20 at 7:28 Shanta Kumar dasShanta Kumar das 416 bronze badges 2
  • 1 And if you log licenseSummary before that last line, it gives you what? – C3roe Commented Mar 20 at 7:45
  • licenseSummary: Base License (New License Issued): , Total Bind: , Total Available: – Shanta Kumar das Commented Mar 20 at 8:40
Add a comment  | 

1 Answer 1

Reset to default 0

The following change correctly print the required data in pdf

var licenseSummary = "Base License (New License Issued): " + newLicenseIssued + ",Total Bind: " + totalBind +",Total Available: " + totalAvailable;
发布评论

评论列表(0)

  1. 暂无评论