word 批量转 pdf 再合并
依赖包
pip install pywin32
pip install PyPDF2
import os
import win32com.client
from PyPDF2 import PdfFileMerger
source_dir = os.getcwd()
wdFormatPDF = 17
word = win32com.client.Dispatch('Word.Application')
for item in os.listdir(source_dir):
if item.endswith(".docx") or item.endswith(".doc"):
inputFile = os.path.join(source_dir,item)
outputFile = os.path.join(source_dir,item.replace(".docx", ".pdf").replace(".doc", ".pdf"))
doc = word.Documents.Open(inputFile)
doc.SaveAs(outputFile, FileFormat=wdFormatPDF)
doc.Close()
word.Quit()
merger = PdfFileMerger()
for item in os.listdir(source_dir):
if item.endswith(".pdf"):
merger.append(item)
merger.write(os.path.join(source_dir,'000.pdf'))
merger.close()
打包
pip install pyinstaller
pyinstaller -F xxx.py
本文来自博客园,作者:weichangk,转载请注明原文链接:https://www.cnblogs.com/weichangk/p/16011154.html