Directly loading custom fonts
See original GitHub issueHi, 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?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:5
Top Results From Across the Web
How To Load and Use Custom Fonts with CSS | DigitalOcean
You can use the @font-face rule to load a custom font on a web page. The history of loading custom fonts has lead...
Read more >The Easy Way to Add Fonts to Your Website (Including ...
How to add custom fonts to your website using @font-face · Step 1: Download the font · Step 2: Create a WebFont Kit...
Read more >The Best Font Loading Strategies and How to Execute Them
Step 1: Use fallback font when web fonts aren't loaded yet. Step 2: Load the Roman (also called “book” or “regular”) version of...
Read more >Using custom fonts using CSS? - Stack Overflow
Generically, you can use a custom font using @font-face in your CSS. Here's a very basic example: @font-face { font-family: 'YourFontName'; ...
Read more >Upload custom fonts | Webflow University
You can add more fonts to your project directly from the Font dropdown in the Style panel. Choose Add fonts, and we'll take...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
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.