Skip to content

Directly loading custom fonts #2830

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

Closed
AuthorSkN opened this issue Jul 30, 2020 · 5 comments
Closed

Directly loading custom fonts #2830

AuthorSkN opened this issue Jul 30, 2020 · 5 comments

Comments

@AuthorSkN
Copy link

AuthorSkN commented Jul 30, 2020

Hi, I need to use a custom font Noto Sans. I would like to loading the font file directly, without converting it in bass64. A file was found in your repository where the font was loaded directly:

if (typeof global === "object" && global.isNode === true) {
      PTSans = doc.loadFile("./test/reference/PTSans.ttf");
} else {
      PTSans = doc.loadFile("base/test/reference/PTSans.ttf");
}
doc.addFileToVFS("PTSans.ttf", PTSans);
doc.addFont("PTSans.ttf", "PTSans", "normal");

I tried uploading my own font file in the example as well. But ran into an error:

jspdf.min.js:29 jsPDF PubSub Error No unicode cmap for font Error: No unicode cmap for font
    at i.registerTTF (jspdf.min.js:262)
   ...

jsPDF PubSub Error Cannot read property 'widths' of undefined TypeError: Cannot read property 'widths' of undefined
    at e.pdfEscape16 (jspdf.min.js:188)
   ....

In this example I tried to loading both directly and via bass64. But only the option for bass64 works.

I was also tried to loading a woff format font in both ways, because this format is of higher priority for me.
But I ran into the same error.

How can I loading the file directly?
Do you support formats other than TTF? Are there any plans for this?

@HackbrettXXX
Copy link
Collaborator

Thanks for the elaborate issue report. When testing with your test project, it doesn't matter which font version I choose, I always get the same error: No unicode cmap for font. I assume your ttf font does not have a unicode map which is required by jsPDF. See my comment on #2710.

jsPDF does only support TTF as font format. Other formats are not supported and there is no plan to support other formats any time soon. We are happy about pull requests from the community, though.

@AuthorSkN
Copy link
Author

Thanks for the answer, I changed the example - removed experiments with the .woff format from there.

The test using base64 works, but loading directly from a file does not work.

To convert to base64 I used your converter i.e. Does he not use the cmap when forming? Do you need a cmap to directly loading?

@AuthorSkN
Copy link
Author

I also added experiment for your tests font "PTSans" and tried to load it the same way you do in a file, but it doesn't work.

How can I get this to work?

@HackbrettXXX
Copy link
Collaborator

Ah, now I could reproduce the issue. I didn't dig into it, but this is already fixed on the current master branch. We will release a new version soon. You can try with the files that are currently in the dist folder.

@github-actions
Copy link

This issue is stale because it has been open 90 days with no activity. It will be closed soon. Please comment/reopen if this issue is still relevant.

@github-actions github-actions bot closed this as completed Nov 6, 2020
gkostov added a commit to gkostov/jsPDF that referenced this issue May 26, 2022
As mentioned in parallax#2830 it is only TrueType that can be embedded
so it's good to make that clear.
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

2 participants