Problem with Screen resolution and zoom in browser when generating pdf file from HTML with JSPDF and Html2Canvas
See original GitHub issueI’m trying to create a script allowing to create a pdf file from an HTML page. I’m using the library jspdf, html2canvas and jquery. It’s working correctly when the zoom in the browser is 100% but I have issues when the screen resolution is changed or if the zoom in the browser is changed.
function generatePDF() {
html2canvas(document.getElementById('content'), { scale: 1, width: 2000, height: 9000 }).then(canvas => {
var imgData = canvas.toDataURL("image/jpeg");
var pdf = new jsPDF('p', 'mm', [520, 1080]);
pdf.addImage(imgData, 'JPEG', 10, 10);
pdf.save("Test.pdf");
});
}
I tried several updates (margin, canvas, …)but I don’t find really a solution for that.
Could you please help me with that ?
Thanks in advance for your help.
Issue Analytics
- State:
- Created 3 years ago
- Comments:25 (5 by maintainers)
Top Results From Across the Web
Problem with Screen resolution and zoom in browser when ...
I'm trying to create a script allowing to create a pdf file from an HTML page. I'm using the library jspdf, html2canvas and...
Read more >Using jspdf to save html page as pdf, saved pdf contains ...
Here is how I managed to get the full page pdf while the page is zoomed in using jsPDF's new .html() method. First,...
Read more >html2pdf.js | Client-side HTML-to-PDF rendering using pure JS.
html2pdf.js converts any webpage or element into a printable PDF entirely client-side using html2canvas and jsPDF. :warning: There have been several issues ......
Read more >Angular 13 jsPDF & Html2Canvas Project to Export ... - YouTube
Angular 13 jsPDF & Html2Canvas Project to Export HTML Canvas With Background Image With Text & CSS.
Read more >Print to scale example - OpenLayers
Example of printing a map to a specified scale. The print is exported as a PDF using the jsPDF library. Unlike the Export...
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
Hi,
It’s me again. I’m using this version of jspdf: jspdf.pr2665.js (see the example on http://weihuiguo.com/) for getting a first example for creating the pdf file.
My code there with the updates from this post:
It’s working correctly after applying your comment from this page.
If I replace jspdf.pr2665.js by jspdf.js from the folder src on the master branch, the code is not working (the error “pdf.html is not a function”, could you help me please ? I don’t know what is the problem and how to solve that. Regards,
Thank you very much it’s working now 😃