Reputation: 1107
I use phantomjs and puppeteer on the same system. I am using a font file to support emoji in PDF exports. phantomjs crashed when I use that font, but not chromium browser used in puppeteer. Is there any way I can load the font file specifically for chrome only without making the font apply system wide from /usr/share/fonts
. I am on CentOS 7 machine.
Upvotes: 0
Views: 385
Reputation: 29037
You can convert the font into a web font, and then embed the font into the web page using page.addStyleTag()
:
await page.addStyleTag({
'content' : `
@font-face {
font-family:'[font-name]';
src:url('[font-file].woff2') format('woff2'),
url('[font-file].woff') format('woff');
font-weight:normal;
font-style:normal;
}
`
});
Then, you can run page.pdf()
to download the web page as a PDF containing your custom font.
This will allow you to use the font on a case-by-case basis without needing to install it on your machine.
Upvotes: 1