DEV Community

Cover image for AWS Lambda and Puppeteer: Fonts for Emoji + Non-Latin
Tarwin Stroh-Spijer
Tarwin Stroh-Spijer

Posted on

AWS Lambda and Puppeteer: Fonts for Emoji + Non-Latin

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.

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.

Screenshot of a directory showing font files

  • 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

import chromium from '@sparticuz/chromium'
import puppeteer from 'puppeteer-core'
Enter fullscreen mode Exit fullscreen mode
  • 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)