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

Letter spacing #1575

Closed
ovidiu-balau opened this issue Jan 5, 2018 · 16 comments
Closed

Letter spacing #1575

ovidiu-balau opened this issue Jan 5, 2018 · 16 comments

Comments

@ovidiu-balau
Copy link

Hi,

Is there any way to change the letter spacing and reduce the original one?

Thank you.

@Uzlopak
Copy link
Collaborator

Uzlopak commented Jan 5, 2018

Nope.
#1448 has the ability to set charSpace

@Uzlopak
Copy link
Collaborator

Uzlopak commented Feb 20, 2018

CharSpace parameter added to jspdf by #1433

Will be part of next release

@Uzlopak Uzlopak closed this as completed Feb 20, 2018
@nataliawww
Copy link

nataliawww commented May 4, 2018

Just FIY doc.setCharSpace() is the way to do it

@Uzlopak
Copy link
Collaborator

Uzlopak commented May 8, 2018

doc.setCharSpace sets the charspace in the whole document. If you want to set the charSpace of a specific text you need to set it like I wrote above.

@viraj4422
Copy link

viraj4422 commented Jan 29, 2019

@arasabbasi Could you please post an example of setting charSpace for specific text ?

This sets charSpace for entire doc:
doc.text('test', 0, 0,{charSpace: '0.9'});

@Uzlopak Uzlopak reopened this Jan 30, 2019
@Uzlopak
Copy link
Collaborator

Uzlopak commented Jan 30, 2019

Really? Hmm. Has to be examined

@Uzlopak
Copy link
Collaborator

Uzlopak commented Mar 24, 2019

After more than a year I examined it and figured it out, that it was indeed setting charSpace globally.

Bugfix #2349

@Uzlopak Uzlopak closed this as completed Mar 24, 2019
Uzlopak added a commit that referenced this issue Mar 24, 2019
* fix sanitization error

* fix the fix
@Mertakus
Copy link

I'm on jspdf 1.5.3 but this:

doc.text('Test', 10, 10, { charSpace: '3' });

still adds the charSpace throughout the whole document :-S instead of just on that line. Any idea why?

@HackbrettXXX
Copy link
Collaborator

It could be that this is fixed but not yet released. Could you test it with the file that are currently in the dist folder on the master branch?

@Mertakus
Copy link

It could be that this is fixed but not yet released. Could you test it with the file that are currently in the dist folder on the master branch?

Hi, thank you for your answer. I'm a bit of a pleb. Could you explain in a few short steps how I can do that? I've tried the following:

(my application is in node)
I created a new file jspdfDist.js, I then copied all the code from this file --> https://raw.githubusercontent.com/MrRio/jsPDF/master/dist/jspdf.node.min.js - into the jspdfDist.js file.

I then tried importing it with: import jsPDF from './jspdfDist' --> this gives me the following error:

This dependency was not found:
* btoa in ./src/components/templates/jspdfDist.js

Maybe I am doing it all wrong, idk :-S.

@RensTillmann
Copy link

RensTillmann commented Oct 17, 2020

I'd like to share something I discovered (see image). I will try to explain what I am doing. Basically I am generating an image with html2canvas of the page. Since this will not make the PDF searchable (no text is in the PDF) I manually add text with doc.text(). This works great, but there is something odd when the text that is rendered in the PDF contains a combination of "Te" or "Ye", it seems the charSpace for the character "T" and "Y" have more spacing so to speak compared to other characters. Basically what I am trying to say here is that there is a difference in "letter spacing/charSpace" between what the browsers displays and what is rendered when using doc.text(). Now I am rendering the text invisible that is drawn by doc.text() so it's not that big of an issue you'd think. But the offset would become larger and larger the more "T" and/or "Y" characters are being used in the document.

I have also been trying to find a custom ttf font that works, but they all seem to be having the exact same issue. Perhaps it's an issue with "PDF" file type itself here? Any ideas?

Anyway, I am probably going to have to do a work-around which would be: before generating the image with html2canvas I'd set any text to opacity: 0, to make it invisible in the image, and then draw the text on the location with a slightly smaller charSpace than the original text. It's not the best way of doing things, but I don't see any other solution for my problem right now. Any suggestion are highly appreciated as in what could be causing this, and if there is something else I could try .

ps. the red text in the image is the drawn text with the use of doc.text(), and the grey text is from the image created with html2canvas.

Thanks!

letter-spacing-charspace

@HackbrettXXX
Copy link
Collaborator

@RensTillmann this could very well be a bug in jsPDF. Maybe it doesn't recognize the kerning between "T" and "e".

@olemp
Copy link

olemp commented Feb 12, 2021

@HackbrettXXX @RensTillmann Having some of the same issues. Found a solution yet?

image

@HackbrettXXX
Copy link
Collaborator

@olemp not that I know of. Would be awesome if you or someone else could look into that :)

@devinnogenio2
Copy link

any solution in 2023?

@shrinker03
Copy link

any solution in 2023?

Did you find any solution?

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

No branches or pull requests

10 participants