jsPDF icon indicating copy to clipboard operation
jsPDF copied to clipboard

Centering a multiline rotated text isn't working

Open StriderRanger opened this issue 4 years ago • 6 comments

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 align is.
  • In my example I am using the version 2.2.0 of jspdf since 2.3.1 isn't working on stackblitz. But in my development environment I am using 2.3.1, and I am facing the same problem.

Thanks!

StriderRanger avatar Jul 09 '21 17:07 StriderRanger

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 ;)

HackbrettXXX avatar Jul 12 '21 09:07 HackbrettXXX

😊 "I'd be delighted to work on this issue, @StriderRanger ! Could you please assign it to me?"

TechWizard9999 avatar Sep 30 '23 21:09 TechWizard9999

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.

StriderRanger avatar Oct 01 '23 10:10 StriderRanger