feat: add configurable watermark text in API settings

This commit is contained in:
hmo
2026-04-27 20:14:17 +08:00
parent 1c9d539653
commit c8d77187d1
3 changed files with 13 additions and 4 deletions
+3 -3
View File
@@ -192,7 +192,7 @@ class PianoPDF:
self.elements.append(Spacer(1, 5*mm))
def generate_pdf(plan_id, student_name, content, output_dir, rendered_report=None):
def generate_pdf(plan_id, student_name, content, output_dir, rendered_report=None, watermark_text=None):
"""生成PDF文件"""
os.makedirs(output_dir, exist_ok=True)
output_path = os.path.join(output_dir, f"plan_{plan_id}.pdf")
@@ -272,7 +272,7 @@ def generate_pdf(plan_id, student_name, content, output_dir, rendered_report=Non
# 水印函数(每页都绘制)
def draw_watermark(c, doc):
if not CHINESE_FONT_OK:
if not watermark_text or not CHINESE_FONT_OK:
return
c.saveState()
try:
@@ -283,7 +283,7 @@ def generate_pdf(plan_id, student_name, content, output_dir, rendered_report=Non
c.translate(A4[0]/2, A4[1]/2)
c.rotate(45)
# 绘制水印文字(居中)
c.drawCentredString(0, 0, "仅供学习参考")
c.drawCentredString(0, 0, watermark_text)
except Exception:
pass # 字体问题则跳过水印
c.restoreState()