Skip to content

Issue with custom font - Myriad-Pro-Bold #2921

Closed
@samuraitruong

Description

@samuraitruong

I try to add custom font but it seem doesn't work with all font

I can get Roboto.ttf work but it doesn't work with this font - https://fontsgeek.com/fonts/Myriad-Pro-Bold

Got below error

sPDF PubSub Error Cannot use 'in' operator to search for '0' in undefined TypeError: Cannot use 'in' operator to search for '0' in undefined
    at GlyfTable.glyphFor (/Users/truongnguyen/Truong/pdf-generator/node_modules/jspdf/dist/jspdf.node.js:35270:12)
    at Subset.glyphsFor (/Users/truongnguyen/Truong/pdf-generator/node_modules/jspdf/dist/jspdf.node.js:35599:35)
    at Subset.encode (/Users/truongnguyen/Truong/pdf-generator/node_modules/jspdf/dist/jspdf.node.js:35638:19)
    at identityHFunction (/Users/truongnguyen/Truong/pdf-generator/node_modules/jspdf/dist/jspdf.node.js:30831:39)
    at Object.<anonymous> (/Users/truongnguyen/Truong/pdf-generator/node_modules/jspdf/dist/jspdf.node.js:30897:7)
    at PubSub.publish (/Users/truongnguyen/Truong/pdf-generator/node_modules/jspdf/dist/jspdf.node.js:404:18)
    at putFont (/Users/truongnguyen/Truong/pdf-generator/node_modules/jspdf/dist/jspdf.node.js:2273:12)
    at putFonts (/Users/truongnguyen/Truong/pdf-generator/node_modules/jspdf/dist/jspdf.node.js:2304:11)
    at putResources (/Users/truongnguyen/Truong/pdf-generator/node_modules/jspdf/dist/jspdf.node.js:2659:5)
    at API.__private__.buildDocument (/Users/truongnguyen/Truong/pdf-generator/node_modules/jspdf/dist/jspdf.node.js:3232:5)

Here is the code I added all the front

addFonts() {
    const fonts = fs.readdirSync('./fonts');
    for (const font of fonts) {
      const base64Front = fs.readFileSync('./fonts/' + font).toString('base64');

      this.doc.addFileToVFS(font, base64Front);
      const arr = font.split('.')[0].split('-');
      this.doc.addFont(font, arr[0], arr[1].toLocaleLowerCase());
    }
  }

Do we have the list or the requirements for the custom font support?

I already try fontconverter provided in other issue and compare base64 are same

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