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?