There is a task - to dynamically generate a string with html code and on the basis of it to generate a pdf file (using the html-pdf package). Naturally, everything in this pdf should be styled as the customer wants.

The customer provides otf files of fonts that are needed.

Inside the style tag, I embed the following line:

import { join } from "path"; const path = join(process.cwd(), "/src/templates/fonts"); export const fonts = ` @font-face { font-family: "proximanova"; src: url("${ path }/ProximaNova/ProximaNova-Regular.otf") format("opentype"); font-style: normal; font-weight: normal; } `; 

I'm testing this whole thing. For completeness, I generate not only a pdf file, but I also place a html file next to it.
So when I open the html file in the browser, the fonts are normally picked up.
And in pdf there.

Is it possible to zainlaynit otf file in the style tag?

  • one
    well, translate them to base64 and src: url(data:font/opentype;charset=utf-8;base64,) format("woff"); . only I wouldn’t take a phantom-based work of art; it’s more promising to take github.com/GoogleChrome/puppeteer - nörbörnën February
  • @ örbörnën thanks, now I will get acquainted with this library. And you can argue, what is the disadvantage of the phantom? - muturgan
  • @ örbörnën then I need to read the font file from the disk, convert the resulting buffer to base64 string, and write it after the last comma in the "arguments" of the URL. did I understand you correctly? - muturgan
  • one
    When generating pdf using wkhtmltopdf and puppeteer, the fonts are picked up along the paths and in the base64 - nörbörnën February
  • one

0