feat: add configurable watermark text in API settings
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user