`doc.internal.pageSize.getWidth()` doesn't match measured value
See original GitHub issuefunction pdf() {
const { jsPDF } = window.jspdf;
const doc = new jsPDF("p", "px", "a4");
const pageWidth = doc.internal.pageSize.getWidth();
console.log("pageWidth", pageWidth);
doc.save("pagesize.pdf")
}
You can run the above code here: https://jsfiddle.net/6htnzja8/1/
Running the example code and looking in the console jsPDF says the page width is 446.46 pixels. If I take a screenshot of the generated PDF and measure the size it’s actually 793 pixels wide.
I think the value reported by jsPDF is wrong. Is it, or am I misunderstanding something?
Issue Analytics
- State:
- Created 3 years ago
- Comments:11
Top Results From Across the Web
`doc.internal.pageSize.getWidth()` doesn't match measured ...
Running the example code and looking in the console jsPDF says the page width is 446.46 pixels. If I take a screenshot of...
Read more >How to set image to fit width of the page using jsPDF?
A better solution is to set the doc width/height using the aspect ratio of your image.
Read more >How to get the page width and height ... - iText Knowledge Base
Most of them return an object of type Rectangle that has methods such as getWidth() and getHeight() to get the width and the...
Read more >Export multiple charts to PDF with React and jsPDF
How to export multiple charts into multipage pdf document with React.js ... getWidth(); // if chart do not fit to the page width...
Read more >DataGrid - Pdf Export - Certain options are not applied
then(() => { const pageSize = doc.internal.pageSize; const pageWidth = pageSize.width ? pageSize.width : pageSize.getWidth(); doc.setFontSize(10); ...
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
Is this still working? I am using jsPDF 2.3.1 and trying to put images inside a pdf, but they get blurry. When i try to enable “px_scaling” mentioned here, and https://github.com/MrRio/jsPDF/blob/master/HOTFIX_README.md the code won’t compile. After checking the package, there is no “hotfix” in the code, and the jsPDF constructor only takes “jsPDFOptions”
Edit: I had to pass it in as a constructor parameter, and surpress the statement with // @ts-ignore. It works now properly.
Yeah, for myself and for future reference, I did the math once again:
Which means we have to multiply each pixel by
72/96
to getpt
. So the scaleFactor of72/96
is correct and one has to enable the hotfix in order to get the correct scaling for pixels. We should really document that the hotfix is required for thepx
unit and make this the default with the next major release.Thanks for bringing that up 😉