admin管理员组

文章数量:1406924

I am planning to embed custom font ttf into pdfmake plugin. The documentation remends to add the custom fonts to the vfs_fonts.js file.

 window.pdfMake = window.pdfMake || {}; window.pdfMake.vfs = {
  "Roboto-Italic.ttf": "AAEAAAASAQAABA",
  "Roboto-Medium.ttf": "AAEAAA",
  "MyFont.ttf":"???????????????????"
}

I have MyFont.ttf file but I don't know how to convert that into string/encoded format. Is there anyway to do it programatically through javascript?

I am planning to embed custom font ttf into pdfmake plugin. The documentation remends to add the custom fonts to the vfs_fonts.js file.

 window.pdfMake = window.pdfMake || {}; window.pdfMake.vfs = {
  "Roboto-Italic.ttf": "AAEAAAASAQAABA",
  "Roboto-Medium.ttf": "AAEAAA",
  "MyFont.ttf":"???????????????????"
}

I have MyFont.ttf file but I don't know how to convert that into string/encoded format. Is there anyway to do it programatically through javascript?

Share Improve this question asked Jan 16, 2017 at 23:57 user3501278user3501278 2671 gold badge8 silver badges21 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

It is a base64 format.

There are many tools available online.

Here is one

Programatically :

In JavaScript there are two functions respectively for decoding and encoding base64 strings:

atob()

btoa()

The atob() function decodes a string of data which has been encoded using base-64 encoding.

Conversely, the btoa() function creates a base-64 encoded ASCII string from a "string" of binary data.

source

本文标签: javascriptHow to convert a font file ttf into string data like vfsfontsjs doesStack Overflow