# -*- coding:utf-8 -*-
import os
import PyPDF2
import comtypes.client
# word转pdf
def convert_word_to_pdf(word_path, pdf_path):
"""
word转pdf
:param word_path: word文件路径
:param pdf_path: 生成pdf文件路径
"""
# print("word_path:%s, pdf_path:%s" % (word_path, pdf_path))
word = comtypes.client.CreateObject("Word.Application")
word.Visible = 0
new_pdf = word.Documents.Open(word_path)
new_pdf.SaveAs(pdf_path, FileFormat=17)
new_pdf.Close()
# ppt 转pdf
def convert_ppt_to_pdf(ppt_path, pdf_path):
# print("ppt_path:%s, pdf_path:%s" % (ppt_path, pdf_path))
ppt = comtypes.client.CreateObject("Powerpoint.Application")
ppt.Visible = 1
new_pdf = ppt.Presentations.Open(ppt_path)
new_pdf.SaveAs(pdf_path, FileFormat=32)
new_pdf.Close()
# 统计文件数
def get_all_file_by_type(path, type=(), get_all_dirs=True):
&#
Python统计文件页数
最新推荐文章于 2024-03-19 13:39:52 发布
该Python脚本使用comtypes库将Word和PPT文件转换为PDF,并通过PyPDF2库统计PDF文件的页码。它遍历指定目录下的.docx,.ppt,.pptx文件,生成对应的.pdf,并计算所有PDF的总页数。
摘要由CSDN通过智能技术生成