question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

While Specifying compress : true while creating jsPDF object the result PDF shows garbage character.

See original GitHub issue

While creating jsPDF object with below method shows correct character on PDF var doc = new jsPDF('p','pt','a4'); but while creating object with below method and specifying compression as true it shows garbage character on PDF. var doc = new jsPDF({orientation: 'p',unit: 'pt',format: 'a4',compress : true}); I have used Google Noto CJK font after converting otf to ttf and then done base64 of ttf file by using fontconverter page specified in this repo.

Full function is as per below:

function saveAspdf() {
//var doc = new jsPDF('p','pt','a4',true);
var doc = new jsPDF({orientation: 'p',unit: 'pt',format: 'a4',compress : true});
    doc.setFont('NotoSansAll-Regular'); // set font
    doc.setFontSize(10);
    doc.text('Hello world!', 10, 10);
    //doc.text("在這裡 我們要吃午餐 應用程式類別", 30, 30);
doc.save('a4.pdf');
}

any help on this will be appreciated…

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
saravanacscommented, Dec 12, 2019

@ashakoshti1988 Just try this to reduce file size var data = document.getElementById(‘returnItemsBill’); html2canvas(data).then(canvas => { var imgWidth = 200; var pageHeight = 400; var imgHeight = canvas.height * imgWidth / canvas.width; var heightLeft = imgHeight; var position = 0; const contentDataURL = canvas.toDataURL(‘image/png’,0.3) var pdf = new jspdf(‘p’, ‘mm’, ‘a4’, true); pdf.addImage(contentDataURL, “JPEG”, 5, 0, 200, 287, undefined, ‘FAST’); while (heightLeft >= 0) { position = heightLeft - imgHeight; pdf.addPage(); pdf.addImage(contentDataURL, “JPEG”, 5, 0, 200, 287, undefined, ‘FAST’); heightLeft -= pageHeight; } pdf.save(“Sales_Bill_Original”); });

Happy Coding …!!

0reactions
marcohamersmacommented, Jul 6, 2020

I’ve encountered this issue as well with non-latin characters. For me, image compression seems to go a long way in reducing the filesize, but the compression would probaly be even better.

Read more comments on GitHub >

github_iconTop Results From Across the Web

While Specifying compress : true while creating jsPDF object ...
var doc = new jsPDF('p','pt','a4'); but while creating object with below method and specifying compression as true it shows garbage character on ...
Read more >
jsPDF table example - Unsaved project - Plunker
The methods / properties you add will show up in new jsPDF objects. * * One property is prepopulated. It is the 'events'...
Read more >
前端使用jspdf生成PDF通过ajax传输后台生成PDF文件
addImage(pageData, 'JPEG', 0, 0, imgWidth, imgHeight) } else { // 分页 while (leftHeight > 0) { pdf.addImage(pageData, 'JPEG', 0, position, ...
Read more >
jspdf - UNPKG
So, while we still cannot display\n * 2-byte characters property, ... A name object specifying how the document should be displayed when opened:\n...
Read more >
Generating PDF using multiple google charts and jspdf
1 Answer 1 ; var doc = new jsPDF ; true); //true is set for pdf compression return ; then(function(pageNumber) ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found