[BUG] Can't get custom font to load on Google Function
See original GitHub issueEnvironment
chrome-aws-lambda
Version: 5.2.1puppeteer
/puppeteer-core
Version: 5.2.1- OS:
- Node.js Version: 10
- Lambda / GCF Runtime: 10
Expected Behavior
The custom google font should load on my page as it’s rendered to PDF.
I’m having a hard time using the font
function to load a custom font. I’m using Google firebase functions.
Here’s my server code:
await chromium.font('https://fonts.googleapis.com/css2?family=Josefin+Sans');
const browser = await chromium.puppeteer.launch({
args: chromium.args,
defaultViewport: chromium.defaultViewport,
executablePath: (config.app && config.app.firebase_chromium_exe_path) || await chromium.executablePath,
headless: chromium.headless,
ignoreHTTPSErrors: true,
});
const page = await browser.newPage();
await page.setContent(data);
const pdfBuffer = await page.pdf({ printBackground: true });
res.set("Content-Type", "application/pdf");
res.status(200).send(pdfBuffer);
await browser.close();
data
is pointing to a raw HTML file. For this example I’ll use:
<!DOCTYPE html>
<html>
<head>
<style>
* {
font-family: 'Josefin Sans';
font-size: 100px;
}
</style>
</head>
<body>
This should be in Roboto
</body>
</html>
Am I just doing something wrong? How exactly are we able to access the fonts that are pre-loaded?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:10
Top Results From Across the Web
Troubleshooting | Google Fonts
Potential Cause. There is an error in the API URL, or a style that is not supported by the font has been requested....
Read more >Google Fonts are not rendering on Google Chrome
When I first load up the website in Google Chrome, texts using that custom font are NOT displayed AT ALL (even tho font-stack...
Read more >How to load web fonts to avoid performance issues and speed ...
Custom web fonts are used everywhere around the world, but many (oh so many) sites load them improperly. This causes a lot of...
Read more >How to Load Fonts in a Way That Fights FOUT and Makes ...
A web font workflow is simple, right? Choose a few nice-looking web-ready fonts, get the HTML or CSS code snippet, plop it in...
Read more >How to Use Google Fonts and Custom Fonts in Jotform
Getting Your Google Fonts Import Code · Click the icon on the top-right corner of the page to open the Selected family panel....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@mohamad-agha .font seems to work for me.
await chromium.font('https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap')
will not work because it links to a css, and not a valid ttf fontTry like this:
chromium.font('https://rawcdn.githack.com/openmaptiles/fonts/e1c6ea642b612abcbdd6e48fc2400162c1b531da/roboto/Roboto-Regular.ttf?raw=true')
Hey @dejwid have you found a solution for this?