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 剛發表






