-
-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Font Family CSS not working with Puppeteer #33
Comments
Lambda is so stripped down that it doesn't include all the base web fonts. Personally I've never added any custom fonts so I'm not even sure the code for that still works. If you want to test it out and report back that would be helpful. See this for more info https://medium.com/creditorwatch/aws-lambda-fonts-libfontconfig-5e837281a4ce |
I'm loading custom fonts via a lambda layer in my app using the instructions from the readme. Works great! |
@Sparticuz thank you for the info. I have just tried with lambda layers as per @jznadams suggestion, but it doesnt seem to be working. @jznadams How are you referencing your fonts? I followed the instructions in the readme and have attached my lambda layer to my function, but when I use the CSS |
Note that if you are trying to render any emoji at all you then you will have to explicitly provide an emoji font of some kind because that's entirely missing from the base lambda. Noto Color Emoji works fine for that. |
@jznadams Thank you for the detailed explanation! Turns out I did create the lambda layer correctly but I wasn't looking close enough and my fonts are actually changing (The fonts I chose are relatively similar). So in the end, the lambda layer instructions in the README do work correctly. I appreciate the help from both of you and @Sparticuz for creating this package. Thanks! |
As another data point / way to do it for people who find this via search. I have the following in my lambda Dockerfile: FROM public.ecr.aws/lambda/nodejs:18-x86_64
RUN yum install -y google-noto-sans* google-noto-emoji*
# ... This wasn't working until I explicitly set the process.env.FONTCONFIG_PATH = '/etc/fonts';
chromium = require('@sparticuz/chromium'); Then my html and saved PDF had the correct fonts. |
@jznadams Thanks for your explaination, I've tried it as well, but the fonts still can not work. Is it needed to add await chromium.fonts(xxx) in the code? |
@xjtroddy No await is necessary. Double check these things:
|
A pretty simple way I found if using Google Fonts or similar: Load fonts in head:
And then wait for the content to be loaded:
|
Looks like this might have been addressed by the Puppeteer team puppeteer/puppeteer#12175 |
Environment
chromium
Version: 109.0.1puppeteer
/puppeteer-core
Version: 19.4.1Description
I am using this chromium package along with puppeteer-core to generate PDFs from HTML on lambda with the serverless framework. I am using a couple different CSS fonts based on user input (Times New Roman, Calibri, Monospace, etc) but I am not getting any change in the PDF when I change the font-family value in the CSS for my HTML (all other CSS works). It should be noted that this works perfectly fine when I am running it on my own local machine.
I did notice the Fonts section of the readme for this repo, but I dont want to download any custom fonts, I just want the default CSS fonts which I mentioned above. Am I missing something? If anyone could help me out I would really appreciate it. Thank you.
The text was updated successfully, but these errors were encountered: