The problem
If you want to create PDFs or screenshots of sites the best solution is Puppeteer (https://pptr.dev/). The problem is that if you have Emojis or languages such CJK (Chinese, Japanese, Korean) they are not included in the default layers provided.
Chromium Layer
The easiest way is to use package created by Sparticuz. It's small enough to fit in a Lambda Layer etc.
download chromium layer from here:
https://github.com/Sparticuz/chromium/releasesupload chromium layer to S3 bucket
create lambda layer from chromium layer in S3 bucket
Fonts layer
Sparticuz/chromium does not include any fonts other than Open Sans. Will need fonts for emojis, and langs such as CJK.
I suggest using the font Noto by Google. You can see in my example directory I have NotoSansJP (for Japanese) NotoColorEmoji.
- add font files to a
fonts
folder - run
zip -9 --filesync --move --recurse-paths fonts.zip fonts/
in your CLI. - create lambda layer from
fonts.zip
Creating the Lambda
-
install
puppeteer-core
- the version will depend on your chromium version- https://pptr.dev/supported-browsers
npm i puppeteer-core@v24.0.0
Add the following to file:
import chromium from '@sparticuz/chromium'
import puppeteer from 'puppeteer-core'
- Attach both the Chromium and Fonts layers to your Lambda
Fonts will be automatically loaded from the /fonts
directory in your attachd layer..
Top comments (0)