I am using puppeteer to generate pdf, with following development environment:
Local environment:
Server environment:
The issue i am facing is that the PDf generated from server is large in size and also font won't load. The results are as below PDFs.
Please note the below HTML is being copied form the html file i am being using to create PDF (as URL). [I am using URL for page.goto to generate PDF].
<html>
<body>
FOOOO <span style="font-family: Impact, Charcoal">impact</span>
<span style="font-family: 'Courier New', Courier, monospace">courier</span>
</body>
</html>
Code snippets is as follows:
const config = {
headless: true,
ignoreHTTPSErrors: true,
args: [
'--no-sandbox',
'--disable-setuid-sandbox',
'--disable-dev-shm-usage'
],
};
browser = await puppeteer.launch(config);
page = await browser.newPage({ context: 'another-context' });
await page.goto(pageURL, {timeout: 50000,waitUntil: ['domcontentloaded','networkidle0']});
await page.emulateMedia('screen');
const pdfOptions = {
format,
pageRanges,
printBackground:true
}
const pdf = await page.pdf(pdfOptions);
I anything missing in the environment, i am kind of novice for Centos (if anything missing). Please help, as i am unable to find out what is missing here.
What is the expected result? The PDF created over local and server should be the same. Same font and size for the same code.
What happens instead? The server PDf generated is larger than local and do not load PDF.
Fonts are not included in the server PDF because its a linux server and it doesn't have Windows fonts. According to this answer you can install those fonts:
yum install curl cabextract xorg-x11-font-utils fontconfig
yum install https://downloads.sourceforge.net/project/mscorefonts2/rpms/msttcore-fonts-installer-2.6-1.noarch.rpm
See also: http://mscorefonts2.sourceforge.net/