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.

splitTextToSize uses inverse scale factor

See original GitHub issue

The documentation of splitTextToSize states it uses “measurement units declared as default for the jsPDF instance”. Thus when I define the constructor

let doc = new jsPDF('p', 'px', 'a4');

a line that spans the entire page should be 595.28pt * 96 / 72 = ~793.7 pixels wide. One would then expect that

let splitText = doc.splitTextToSize(longText, 793.7);
doc.text(splitText, 0, 0)

produces lines that spans the entire page, but this not the case.

A page-spanning line is achieved at ~446 pixels like so

let splitText = doc.splitTextToSize(longText, 446);
doc.text(splitText, 0, 0)

Now, 446 happens to be 595.28 / (96 / 72), or 595.28 * (72/96), leading me to conclude that, somehow, an inverse scale factor is being applied between pt and px when adding text

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
HackbrettXXXcommented, Aug 16, 2021

The ‘px’ scaling factor is wrong per default. Try enabling the px_scaling hotfix and see if this gives the expected result.

0reactions
HackbrettXXXcommented, Aug 18, 2021

It’s documented in the jsPDF constructor API doc: http://raw.githack.com/MrRio/jsPDF/master/docs/jsPDF.html, but yeah, mentioning it in the readme as well is probably a good idea.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The Inverse Scale Factor in Isotropic Quantum Geometry - arXiv
This procedure results in a bounded operator which is diagonalizable simultaneously with the volume operator and whose eigenvalues are ...
Read more >
How do I use Text Scale Factor property in flutter
You can use MediaQuery.of(context).textScaleFactor but I think using auto_size_text is more efficient. EDIT 2 :
Read more >
jspdf.js - Documentation
@param unit {String} Measurement unit to be used when coordinates are specified. ... gStatesMap = {}, // see fonts; activeGState = null,; k,...
Read more >
Calculate the Inverse of a Combined Scale Factor
I have a drawing that needs to be scaled (using the scale command) by a global scale factor of 0.99975185, so I need...
Read more >
jspdf.js - Documentation - GitHub Pages
If you want to use your own format just pass instead of one of the above ... var activeGState = null;; var k;...
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