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.55k stars 544 forks source link

Loading custom fonts #394

Open inamvar opened 6 years ago

inamvar commented 6 years ago

I'm using Persian fonts like IRANSANS. can I import my custom font ?

joassouza commented 6 years ago

This can help you https://github.com/marcbachmann/node-html-pdf/issues/322#issuecomment-327045134

hosseinnedaee commented 3 years ago

I had the same problem and solved it by using file:// in my html code, for example, I imported my font-face declration css file in them main like this: <style> @import url("file:///home/myname/projects/myprojectname/public/font/IRANSansWeb/index.css"); </style> the base option doesn't word for me.

Dozalex commented 1 year ago

If you use docker, this solution works

1) install fonts globally

COPY ./my-custom-font.ttf ./
RUN mkdir -p /usr/share/fonts/truetype/
RUN install -m644 my-custom-font.ttf /usr/share/fonts/truetype/
RUN rm ./my-custom-font.ttf

2) just use this font in font-family without imports