fix: remove trailing spacers before PDF build to avoid blank last page

This commit is contained in:
hmo
2026-04-27 21:19:35 +08:00
parent 0898e2da8f
commit 8ae7def939
2 changed files with 7 additions and 2 deletions
+5 -1
View File
@@ -278,7 +278,7 @@ def generate_pdf(plan_id, student_name, content, output_dir, rendered_report=Non
return
c.saveState()
try:
c.setFont("Chinese", 14)
c.setFont("Chinese", 56)
# 浅灰色半透明
c.setFillColor(colors.Color(0.6, 0.6, 0.6, alpha=0.25))
# 旋转45度
@@ -290,5 +290,9 @@ def generate_pdf(plan_id, student_name, content, output_dir, rendered_report=Non
pass
c.restoreState()
# 移除末尾的空白元素(避免产生多余空白页)
while pdf.elements and isinstance(pdf.elements[-1], Spacer):
pdf.elements.pop()
doc.build(pdf.elements, onFirstPage=draw_watermark, onLaterPages=draw_watermark)
return output_path