0

So I have a Japanese OTF font MPLUS2 Regular TTF . I have used a tool called woff tools available in npm to convert this to woff format. I link this font through css

@font-face {
        font-family: "M PLUS 2";
        src: url('output.woff') format('woff');
    }

everything works fine now and looks something like this sample . However I require to convert this to base64 and embed it into the css , something like this

@font-face {
    font-family: 'M PLUS 2';
    src: url(data:font/woff;charset=utf-8;base64,<<base64 string>>) format('woff');
}

When I convert this to base64 and use it , I get an output like this sample

I used the Buffer method to convert this :

const fString = fs.readFileSync(path.join(__dirname,font_name)).toString('utf-8');
const base64 = Buffer.from(fString).toString('base64');

How do I properly convert this to base64?

  • Does this answer your question? [ReadFile in Base64 Nodejs](https://stackoverflow.com/questions/28834835/readfile-in-base64-nodejs) – Karl-Johan Sjögren Nov 25 '21 at 09:15
  • Hi, I have tried what was suggested in the link , to read it as base64 from fs directly, unfortunately did not work ,same issue as mentioned in the question – Akash Srinivas Nov 25 '21 at 09:21

0 Answers0