marcbachmann / node-html-pdf

This repo isn't maintained anymore as phantomjs got dreprecated a long time ago. Please migrate to headless chrome/puppeteer.
MIT License
3.56k stars 545 forks source link

Unable to embed custom fonts - Fonts getting vectorized #656

Closed marco910 closed 2 years ago

marco910 commented 2 years ago

Hi community,

I'm trying to embed custom fonts in a pdf. In basic it is working that the fonts are being used in the PDF but the text I'm applying a custom font to get's converted to vectors. How can I prevent this?

When I generate the PDF and open it in Acrobat I can see under "Fonts" only the "DejaVuSans" font. How can I remove this default font and embed my custom font?

@marcbachmann I saw you businesscard example where you're using a custom font that is also embedded into the PDF. How did you get this working?

marco910 commented 2 years ago

I solved my issue by doing the following:

  1. For example, my font is called "Permanent Marker".
  2. Open the path /usr/share/fonts/ on your Ubuntu machine.
  3. Create a new folder with the name of your font-format or just use "truetype" in case of TTF font.
  4. Create a new folder inside the folder of 3. with the name of your font and copy all files to that folder.
  5. Type fc-list in your command line on the same machine to list all fonts that are installed on the machine.
  6. Note the name and style of the font.
  7. Create a new <style></style> in the <head> of your HTML template and apply the font using font-family: "%name_of_your_font%"; and font-style: %font_style%.