While Specifying compress : true while creating jsPDF object the result PDF shows garbage character.
See original GitHub issueWhile 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:
- Created 4 years ago
- Comments:5
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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 …!!
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.