forked from Dawn_Ocean/ZJUEVA-Reimburse
增加了同时生成.pdf文件的功能
This commit is contained in:
@@ -4,6 +4,9 @@ from docx.shared import Inches, Pt
|
|||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
import fitz
|
import fitz
|
||||||
|
|
||||||
|
import pdfkit
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
types = "abc"
|
types = "abc"
|
||||||
@@ -82,6 +85,15 @@ def pdf2img(pdf_path, pdf_name, zoom_x = 3, zoom_y = 3):
|
|||||||
pix.save(pdf_name[:-4] + '.png') # 将图像存储为PNG格式
|
pix.save(pdf_name[:-4] + '.png') # 将图像存储为PNG格式
|
||||||
doc.close() # 关闭文档
|
doc.close() # 关闭文档
|
||||||
|
|
||||||
|
def docx2pdf(doc_file = "output.docx", html_file = "output.html"):
|
||||||
|
doc = Document(doc_file)
|
||||||
|
full_text = ""
|
||||||
|
for para in doc.paragraphs:
|
||||||
|
full_text += para.text + "\n"
|
||||||
|
with open(html_file, "w", encoding="utf-8") as file:
|
||||||
|
file.write(full_text)
|
||||||
|
pdfkit.from_file(html_file, "output.pdf")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
print("在使用该脚本前,请将发票、付款记录、购买记录按以下规则命名:")
|
print("在使用该脚本前,请将发票、付款记录、购买记录按以下规则命名:")
|
||||||
print("在文件名前添加[两位数字][类型]")
|
print("在文件名前添加[两位数字][类型]")
|
||||||
@@ -89,4 +101,5 @@ if __name__ == "__main__":
|
|||||||
print("如:02b小公仔付款.png 代表第二份材料中的付款记录")
|
print("如:02b小公仔付款.png 代表第二份材料中的付款记录")
|
||||||
convert()
|
convert()
|
||||||
gen_docx()
|
gen_docx()
|
||||||
|
docx2pdf()
|
||||||
|
|
||||||
Reference in New Issue
Block a user