Broken Font on AWS Lambda

Rendering a PDF document in Linux could result in broken characters, as shown in the image below. Sometimes the characters appear to render properly on a Windows environment, but not on Linux.

Broken Character

Reason

The reason is that the font is missing from the operating system.

Solutions

If you already know the font name, that's great you can skip step 1.

  1. To find the font name, try rendering the HTML on Windows and use Adobe to inspect the characters.
  2. Once the font name is identified, you can download the font file online, such as from Google Font.
  3. To add and install the font via the Dockerfile, place the font in the project and set 'Copy to Output Directory' to 'Copy Always.' Next use the following code add and install in Dockerfile:
# Copy the Cambria Math font into the container
COPY cambria.ttc /usr/share/fonts/

# Install fontconfig to update font cache
RUN dnf install -y fontconfig && \
    fc-cache -fv