AWS Lambda 上的破损字体
This article was translated from English: Does it need improvement?
TranslatedView the article in English
在 Linux 中渲染 PDF 文档可能会导致字符损坏,如下图所示。 有时字符在 Windows 环境中显示正常,但在 Linux 中却不正常。

原因
原因是操作系统缺少该字体。
解决方案
如果您已经知道字体名称,那就很好——您可以跳过步骤 1。
- 要找出字体名称,请尝试在 Windows 上渲染 HTML,并使用 Adobe 检查字符。
- 一旦确定了字体名称,您可以在线下载字体文件,例如从Google Fonts下载。
- 要通过 Dockerfile 添加和安装字体,请将字体放入项目中,并将 '复制到输出目录' 设置为 '始终复制'。接下来,使用以下代码在 Dockerfile 中添加并安装它:
# Copy the Cambria Math font into the container
# Ensure the font file (cambria.ttc) exists in your project directory
COPY cambria.ttc /usr/share/fonts/
# Install fontconfig to update the font cache
# This will install fontconfig and refresh the font cache to recognize the newly added fonts
RUN dnf install -y fontconfig && \
fc-cache -fv解释
COPY cambria.ttc /usr/share/fonts/:此行将 Cambria Math 字体从您的项目目录复制到容器的字体目录中。 确保字体文件(
cambria.ttc)存在于项目目录中。RUN dnf install -y fontconfig && \:此命令安装
fontconfig包,该包对于管理和配置 Linux 中的字体访问是必要的。-y标志自动确认包的安装。- fc-cache -fv:此命令更新字体缓存,确保新复制的字体在容器内的应用程序中可用。 标志
-f(强制)和-v(详细)用于强制重新生成缓存并提供详细输出。
准备开始了吗?
Nuget 下载 16,685,821 | 版本: 2025.12 刚刚发布






