# 一个批量统计pdf、pptx、docx文档页数的Python脚本

**URL:** <https://meta.appinn.net/t/topic/84636>\
**Category:** alpha\
**Tags:** windows, python\
**Created:** [2026 年4 月 28 日 13:13 UTC](https://meta.appinn.net/t/topic/84636 "2026-04-28T13:13:08Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

作者： ![VictoryRoad](https://meta-edge.appinn.com/user_avatar/meta.appinn.net/victoryroad/32/58964_2.png) [@VictoryRoad](https://meta.appinn.net/u/VictoryRoad)\
发布日期： [2026 年4 月 28 日 13:13 UTC](https://meta.appinn.net/t/topic/84636/1 "2026-04-28T13:13:08Z")

</div>

## 软件名称

（一个自用的脚本，没有名字 :xyx:）

## 应用平台

Windows

> :warning: 注意：
> 
> 1. 该脚本依赖 MS Word 和 MS PowerPoint 工作，因此只能在 Windows 上运行。
> 2. 该脚本已停止维护，但理论上还能用。

## 推荐类型

【开发者自荐】

## 一句简介

一个统计当前文件夹下所有 pdf 文档、docx 文档以及 pptx 文档总页数的小工具。支持计算双面打印耗纸量。

 ![](https://meta.appinn.net/uploads/default/original/3X/c/c/cc8a06b3527b0107c5e259cd91a4f6c59ff60a8a.png)

## 源代码与下载链接

如果您的电脑上没有 Python，也可以直接使用打包好的二进制文件：

- 下载链接：[https://wwba.lanzoum.com/ilMnh0l0407i](https://wwba.lanzoum.com/ilMnh0l0407i)
- 密码：`h5ta`
- SHA256：`134716f4adc97a5bbb7ef94ec898f233807ff88b0186fe54b5d97590fca0a5af`
- 架构：AMD64

代码很简单。如果您想直接使用该脚本，请先安装 `win32com` 和 `PyPDF3` 两个库：

> **点击此处展开代码**
>
> ```python
> import os
> import math
> from win32com.client import Dispatch
> from PyPDF3 import PdfFileReader
> 
> def get_word_page(word_path):
> word = Dispatch('Word.Application')
> word.Visible = False
> word = word.Documents.Open(word_path)
> word.Repaginate()
> num_of_sheets = word.ComputeStatistics(2)
> return num_of_sheets
> 
> def get_pdf_page(pdf_path):
> filename = pdf_path
> reader = PdfFileReader(filename)
> 
> if reader.isEncrypted:
> reader.decrypt('')
> 
> page = reader.getNumPages()
> return page
> 
> page_sum = 0
> cost_sum = 0
> 
> number_of_docx = 0
> number_of_doc = 0
> number_of_pdf = 0
> page_of_docx = 0
> page_of_doc = 0
> page_of_pdf = 0
> cost_of_docx = 0
> cost_of_doc = 0
> cost_of_pdf = 0
> 
> l=os.listdir('.')
> for file in l:
> if file.endswith('.docx'):
> docfile=f"{os.getcwd()}/{file}"
> docfile=docfile.replace("\\","/")
> p=get_word_page(docfile)
> number_of_docx+=1
> page_of_docx+=p
> cost_of_docx+=math.ceil(p/2)
> if file.endswith('.doc'):
> docfile=f"{os.getcwd()}/{file}"
> docfile=docfile.replace("\\","/")
> p=get_word_page(docfile)
> number_of_doc+=1
> page_of_doc+=p
> cost_of_doc+=math.ceil(p/2)
> if file.endswith('.pdf'):
> p=get_pdf_page(file)
> number_of_pdf+=1
> page_of_pdf+=p
> cost_of_pdf+=math.ceil(p/2)
> 
> page_sum=page_of_doc+page_of_docx+page_of_pdf
> cost_sum=cost_of_doc+cost_of_docx+cost_of_pdf
> 
> print("统计报告")
> print("当前目录下，有：")
> 
> print("docx 文档")
> print(" 文件个数：", number_of_docx)
> print(" 总页数：", page_of_docx)
> print(" 如双面打印，须消耗纸张数：", cost_of_docx)
> 
> print("doc 文档")
> print(" 文件个数：", number_of_doc)
> print(" 总页数：", page_of_doc)
> print(" 如双面打印，须消耗纸张数：", cost_of_doc)
> 
> print("pdf 文档")
> print(" 文件个数：", number_of_pdf)
> print(" 总页数：", page_of_pdf)
> print(" 如双面打印，须消耗纸张数：", cost_of_pdf)
> 
> print("小结")
> print(" 文件总页数：", page_sum)
> print(" 如双面打印所有文档，须消耗纸张数：", cost_sum)
> 
> input("按 Enter 退出。")
> 
> ```

### 附言

这是之前为了[回答一位朋友的问题](https://meta.appinn.net/t/topic/39452)而写的小脚本，感觉可能有点用，就单独发出来了。

不过请注意：本人平时没有精力继续维护这个脚本。如果需要增加更多功能或进行优化，只能请大家自己动手，或借助 AI。
