Provides PDF analysis capabilities including page counting, size analysis, and format statistics using pandas for data processing and analysis
Implements PDF processing tools for analyzing, splitting, merging, compressing, and converting PDF documents to images with comprehensive page and chapter management
Provides a web-based interface for PDF analysis and image processing tools, allowing users to upload files and interact with PDF manipulation functions through a browser
项目介绍
由于项目基于streamlit并打包,打包后的exe文件只发挥python解释器的功能,而代码仍然以.py的python文件存在,在程序运行时才读取.py代码并运行,这就允许用户在pages中不断增加新的.py文件,增加新的功能。
项目结构
已打包的模块
hiddenimports=['streamlit', 'streamlit.web.cli', 'streamlit-sortables', 'pandas', 'PIL', 'PyMuPDF', 'fitz', 'fastmcp', 'PyPDF2', 'tkinter', 'tkinter.filedialog', 'tkinter.simpledialog', 'tkinter.messagebox', 'tkinter.commondialog', 'tkinter.colorchooser', 'tkinter.font', 'tkinter.ttk', 'tkinter.scrolledtext', 'tkinter.dnd', 'tkinter.constants', 'tkinter.tix'],
PDFSizeAnalyzer-MCP
mcp工具介绍
1.统计 PDF 总页数,获取每一页的尺寸(以毫米为单位),同时统计 A3、A4等常见尺寸纸张的数量和页码范围
def analyze_pdf_pages(file_path: str) -> tuple: """ 统计 PDF 总页数,获取每一页的尺寸(以毫米为单位),同时统计 A3、A4等常见尺寸纸张的数量和页码范围。 参数: file_path (str): 单个PDF 文件的路径。 返回: tuple: 包含两个元素的元组,第一个元素是 PDF 的总页数 (int),第二个元素是一个列表 (list), 列表中的每个元素是一个字典,包含纸张尺寸、纸张类型、总页数和页码范围。 """
2.将 PDF 的每一页转换为图片,并保存到以 PDF 名称命名的文件夹中。
def convert_pdf_to_images(file_path: str)-> list: """ 将 PDF 的每一页转换为图片,并保存到以 PDF 名称命名的文件夹中。 参数: file_path (str): 单个 PDF 文件的路径。 返回: list: 包含所有生成图片文件路径的列表。 """
3.根据用户选择的章节拆分PDF文件,返回保存路径的字典列表。
def split_pdf_by_chapters(file_path: str, selected_chapters=None) -> list: """ 根据用户选择的章节拆分PDF文件。
4.从PDF中提取章节标题及其起始和结束页码。
def extract_pdf_chapters(file_path: str)-> list: """ 从PDF中提取章节标题及其起始和结束页码。
5.根据用户输入的页码范围将PDF分隔成多个单独的PDF文件。
def split_pdf_by_user_input(file_path: str, user_input: str) -> list: """ 根据用户输入的页码范围将PDF分隔成多个单独的PDF文件。
6.压缩PDF文件,将PDF文件转换为图片型PDF,通过控制图片质量1-100实现体积压缩
def compress_pdf(file_path: str, quality: int = 75) -> str: """ PDF文件压缩(图片型)
7.压缩PDF文件,通过删除不必要的元素实现体积压缩
def optimize_pdf(file_path: str) -> str: """ PDF优化压缩(文本保留型)
8.合并PDF文件
def merge_pdfs(file_paths: list, output_path: str) -> str: """ 合并多个PDF文件为一个PDF文件
安装教程
1. 进入项目目录
在 Windows 系统中,可以使用以下命令进入项目目录:
2. 创建虚拟环境
在 Windows 系统中,可以使用以下命令创建并激活虚拟环境:
3. 安装依赖
可以使用以下命令安装:
4. 生成配置文件(以Trae为例)
运行 生成mcp服务需要的配置文件.py
文件生成 mcp_config.json
:
在命令行中执行
将自动生成 mcp_config.json
文件,内容如下:
使用说明
mcp使用说明
- 确保已经按照安装教程完成环境配置。
- 在'Trae'软件中,新增MCP,填入配置json内容。
- 测试运行,确保配置正确。
- 测试1:调用mcp服务,告诉我一下这个pdf文件的页数,按打印尺寸分别统计下页数和页码.
本地浏览器使用说明
- 用streamlit运行PDF.py
- 根据运行窗口生成的网址,或自动打开的网址,在浏览器中打开。
- 上传pdf文件,根据需求点击按钮,结果展示在网页展示,并自动打开结果文件夹。
pyinsaller打包教程
- 激活虚拟环境
- 用spec打包,注意打包streamlit有点不同:
需要额外的run_app.py文件,需要特定的文件夹hooks,这个文件夹内还需要特定的hook-streamlit.py。 当然这些文件的内容都是固定的,不需要自己修改。
有了上面的基础,就可以打包了。注意修改run_app.spec中datas的文件夹路径
- 打包完成后,在 dist 目录下会生成一个可执行文件,但这个执行文件无法运行,还需要把依赖的py文件复制到dist目录下。 本项目中是: PDF.py # 前端主程序 main.py # 后端主程序 pages/子页面的py文件 # 子页面的py文件
注意事项
- 确保使用的是虚拟环境中的 Python 解释器,涉及到依赖问题。
- 先用纯英文目录测试,成功后再测试中文目录。
pages中页面
图片批量旋转与尺寸调整工具
这是整合了谢基海
的代码
功能
- 批量旋转图片:支持批量旋转图片,用户可以选择旋转角度。
- 批量调整尺寸:支持批量调整图片尺寸,用户可以选择调整宽度和高度。
This server cannot be installed
local-only server
The server can only run on the client's local machine because it depends on local resources.
Enables comprehensive PDF analysis and manipulation including page size analysis, chapter extraction, splitting, compression, merging, and conversion to images. Provides both MCP server interface for AI assistants and Streamlit web interface for direct user interaction.
Related MCP Servers
- AsecurityFlicenseAqualityA server providing PDF form manipulation tools via MCP's API, allowing users to find PDFs across directories, extract form field information, and visualize form fields in documents.Last updated -66Python
- AsecurityFlicenseAqualityAn MCP server that provides a tool to extract text content from local PDF files, supporting both standard PDF reading and OCR capabilities with optional page selection.Last updated -117Python
- AsecurityAlicenseAqualityEmpowers AI agents to securely read and extract information (text, metadata, page count) from PDF files within project contexts using a flexible MCP tool.Last updated -1365200TypeScriptMIT License
- -securityFlicense-qualityA PDF processing server that extracts text via normal parsing or OCR, and retrieves images from PDF files through the MCP protocol with a built-in web debugger.Last updated -26Python