jsPDF
jsPDF copied to clipboard
Centering a multiline rotated text isn't working
Hi,
In an Ionic/Angular app, I have a multiline text that is rotated with 45 degree, and when the text has the property align: 'left', the export is working fine. But once I change this property to align: 'center', the result is inappropriate, and the second line of the text moves to the very bottom-left corner of the page.
This is a stackblitz example, where the text has the property align: 'center', and rotated with 45 degree.
Please note that:
- The same problem happens when the alignment is set to
right. - With non rotated text, everything works fine, whatever the value of
alignis. - In my example I am using the version
2.2.0ofjspdfsince2.3.1isn't working on stackblitz. But in my development environment I am using2.3.1, and I am facing the same problem.
Thanks!
Thanks for reporting this bug.
The issue seems to be here: https://github.com/MrRio/jsPDF/blob/cef97fb34eda41a8704c9f3983e680919a328ce4/src/jspdf.js#L3993-L4008
The da array (posX/Y) contains absolute coordinates for the first line and coordinates relative to the previous line for all other lines. This is an issue when passing the coordinates to the generatePosition function. For the non-rotated case, it uses the Td PDF operator, which also accepts relative positions. For the rotated case, it uses the Tm operator, which is not relative to the previous line. See also PDF 1.7 specification, section 9.4.2 Text-Positioning Operators.
Pull requests are welcome ;)
😊 "I'd be delighted to work on this issue, @StriderRanger ! Could you please assign it to me?"
Thanks for looking into this issue @TechWizard9999. I don't have the necessary permissions to assign the issue. It should be done by the repository owners.