diff --git a/module/defense/doc.py b/module/defense/doc.py index 3274926..627f1f4 100644 --- a/module/defense/doc.py +++ b/module/defense/doc.py @@ -2,7 +2,7 @@ import pathlib from copy import deepcopy from docx import Document -from docx.shared import Cm +from docx.shared import Cm, Mm from module.schema import Course, Student @@ -14,6 +14,8 @@ class DocPaper: self._filename = filename section = self._doc.sections[0] + section.page_width = Mm(210) + section.page_height = Mm(297) section.top_margin = Cm(2) section.bottom_margin = Cm(2) section.left_margin = Cm(2) diff --git a/module/worker.py b/module/worker.py index 1625ca7..5994a21 100644 --- a/module/worker.py +++ b/module/worker.py @@ -62,12 +62,14 @@ class DTGWorker(QObject): doc = word.Documents.Open(word_file) try: doc.SaveAs(pdf_file, 17) + doc.Close() os.remove(word_file) os.startfile(pdf_file) except Exception as e: - raise Exception("PDF转换失败,但Word文档已生成") from e - finally: doc.Close() + os.startfile(word_file) + raise Exception("PDF转换失败,但Word文档已生成,已打开Word文档") from e + finally: word.Quit() elif self.output_type == 'word': os.startfile(word_file) diff --git a/template/template.docx b/template/template.docx index bd1785f..9f4b907 100644 Binary files a/template/template.docx and b/template/template.docx differ