Python统计文件页数

该Python脚本使用comtypes库将Word和PPT文件转换为PDF,并通过PyPDF2库统计PDF文件的页码。它遍历指定目录下的.docx,.ppt,.pptx文件,生成对应的.pdf,并计算所有PDF的总页数。
摘要由CSDN通过智能技术生成
# -*- 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):
    &#
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值