fix: pdf gene
This commit is contained in:
@@ -265,6 +265,7 @@ async def _gen_pdf(case_id: UUID, report_dir: Path, body: ReportCreate, db: Asyn
|
||||
from reportlab.lib.styles import getSampleStyleSheet
|
||||
from reportlab.pdfbase import pdfmetrics
|
||||
from reportlab.pdfbase.ttfonts import TTFont
|
||||
from reportlab.pdfbase.cidfonts import UnicodeCIDFont
|
||||
import os
|
||||
|
||||
font_registered = False
|
||||
@@ -282,7 +283,17 @@ async def _gen_pdf(case_id: UUID, report_dir: Path, body: ReportCreate, db: Asyn
|
||||
except Exception:
|
||||
continue
|
||||
|
||||
font_name = "ChineseFont" if font_registered else "Helvetica"
|
||||
if not font_registered:
|
||||
# Docker images often do not ship Chinese system fonts.
|
||||
# Use built-in CID font as a portable fallback.
|
||||
try:
|
||||
pdfmetrics.registerFont(UnicodeCIDFont("STSong-Light"))
|
||||
font_name = "STSong-Light"
|
||||
font_registered = True
|
||||
except Exception:
|
||||
font_name = "Helvetica"
|
||||
else:
|
||||
font_name = "ChineseFont"
|
||||
styles = getSampleStyleSheet()
|
||||
title_style = styles["Title"]
|
||||
title_style.fontName = font_name
|
||||
|
||||
@@ -11,6 +11,7 @@ Pillow==12.1.0
|
||||
httpx==0.28.1
|
||||
openpyxl==3.1.5
|
||||
python-docx==1.2.0
|
||||
reportlab
|
||||
psycopg2-binary==2.9.11
|
||||
|
||||
# dev dependencies
|
||||
|
||||
Reference in New Issue
Block a user