Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Justify text with any custom font does not work #3261

Closed
nApTu3aHs opened this issue Sep 14, 2021 · 6 comments · Fixed by #3285
Closed

Justify text with any custom font does not work #3261

nApTu3aHs opened this issue Sep 14, 2021 · 6 comments · Fixed by #3285

Comments

@nApTu3aHs
Copy link

U can see bug here: https://mrrio.github.io/jsPDF/
Code:

var doc = new jsPDF();
doc.addFont("test/reference/PTSans.ttf", "PTSans", "normal");

doc.setFont("PTSans"); // set font
doc.setFontSize(10);
doc.text("А ну чики брики и в дамки! А ну чики брики и в дамки! А ну чики брики и в дамки! А ну чики брики и в дамки! А ну чики брики и в дамки! А ну чики брики и в дамки! А ну чики брики и в дамки! А ну чики брики и в дамки! А ну чики брики и в дамки! ", 10, 10, {
        align: "justify",
        maxWidth: 100,
});

@HackbrettXXX
Copy link
Collaborator

Thanks for reporting this. A pull request to fix it is very welcome ;)

@owenl131
Copy link
Contributor

owenl131 commented Oct 2, 2021

Hi I would like to look into this!

@owenl131
Copy link
Contributor

owenl131 commented Oct 2, 2021

The word spacing setting (Tw) isn't applied to spaces in multi-byte fonts.

Possible workaround is to toggle between multi-byte fonts and the regular fonts just to apply the right spacing. Shall I go ahead to try this?

https://stackoverflow.com/questions/4063302/pdf-format-word-spacing

@owenl131
Copy link
Contributor

owenl131 commented Oct 2, 2021

image

Works!

@TD-DO
Copy link

TD-DO commented Feb 9, 2022

Thank you so much for solving this! Can someone please merge this so we can use it?

@umwdeveloper
Copy link

Still not working for the following fonts, it works fine if I set font to Helvetica

pdf.setFont('IBMPlexSansArabic-Regular', 'normal') pdf.text('this Agreement, subject to its performance, and in furtherance of the mutual interest and the financial value that Host confirms to have received.', pxToMm(x), pxToMm(y), { maxWidth: pxToMm(getPageWidthInPx() / 2 - 52), align: 'justify', lineHeightFactor: 1.5 })

screenshot-127 0 0 1_5500-2024 02 07-17_32_17

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants