Skip to content

Directly loading custom fonts  #2830

Closed
Closed
@AuthorSkN

Description

@AuthorSkN

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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions