Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ashakoshti1988 opened this issue Dec 3, 2019 · 5 comments

Comments

@ashakoshti1988
Copy link

ashakoshti1988 commented Dec 3, 2019

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..

@saravanacs
Copy link

@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 ..!!

@ashakoshti1988
Copy link
Author

@saravanacs this is my stackoverflow link, https://stackoverflow.com/questions/37677750/pdf-file-size-too-big-created-using-jspdf . this already working with older jsPDF api, but with new jsPDF latest version and google noto fonts compression gives garbage values other than english

@github-actions
Copy link

github-actions bot commented Jul 5, 2020

This issue is stale because it has been open 90 days with no activity. It will be closed soon. Please comment/reopen if this issue is still relevant.

@HackbrettXXX
Copy link
Collaborator

Probably duplicate of #2743.

@marcohamersma
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants