A tool to convert PDF to images and back to PDF
Project description
PDF to Image to PDF Converter (pdf2img2pdf)
这是一个轻量级的 Python 工具,用于将 PDF 文件转换为图像,然后再将这些图像合并回 PDF 文件。适用于需要处理 PDF 内容或修复损坏 PDF 的场景。
功能特性
- 支持将 PDF 文件逐页转换为 PNG 图像。
- 将多张图像合并为一个新的 PDF 文件。
- 跨平台支持(Windows / Linux / macOS)。
- 自动检测依赖项(如 Poppler)并提供清晰的安装指引。
- 支持 PyInstaller 打包后的可执行文件运行。
安装依赖
- Python 依赖库 确保已安装以下 Python 库
pip install pdf2image img2pdf
- Poppler(必需) pdf2image 依赖于 poppler 工具集中的 pdftoppm 命令
Windows 用户:
- 下载预编译版本:Poppler for Windows
- 解压后将 poppler-x.x.x\Library\bin 添加到系统 PATH 环境变量中。
- 或者在代码中显式指定路径(见下方示例)。
Linux 用户:
使用包管理器安装:
# Ubuntu/Debian
sudo apt-get install poppler-utils
# CentOS/RHEL
sudo yum install poppler-utils
macOS 用户:
使用 Homebrew 安装:
brew install poppler
使用方法
命令行调用
python pdf2img2pdf.py <input.pdf> <output.pdf>
作为模块调用
from pdf2img2pdf import convert
# 转换 PDF 文件
convert("example_input.pdf", "example_output.pdf")
注意事项
-
Poppler 必须安装:
如果未安装 poppler,程序会自动检测并提示安装方法。 确保 pdftoppm 或 pdfinfo 命令可在系统中运行。
-
权限问题:
确保脚本对输入文件有读取权限,对输出目录有写入权限。
-
临时文件:
转换过程中会在 tmp/imgs 目录下生成临时图像文件,结束后会自动清理。
-
PyInstaller 支持:
此工具支持打包为独立可执行文件,打包时需确保资源文件路径正确
目录结构
pdf2img2pdf/
├── pdf2img2pdf.py # 主程序文件
├── tmp/ # 临时文件目录(运行时自动生成)
│ └── imgs/ # 存放转换过程中的图像文件
└── README.md # 本文档
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pdf2img2pdf-1.0.0.tar.gz.
File metadata
- Download URL: pdf2img2pdf-1.0.0.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4fea309dc898a8b0d92695387fd9d223e6b7a82177da1ccef24c51d374911824
|
|
| MD5 |
ec3f95b29216f10d2c7755b633d06725
|
|
| BLAKE2b-256 |
0b86993033ba75a25aebea249e9baf4bc97950251c55978a9f94022ff0f19026
|
File details
Details for the file pdf2img2pdf-1.0.0-py3-none-any.whl.
File metadata
- Download URL: pdf2img2pdf-1.0.0-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
90cb090d132cb86c06a73fbd3600bd56e1f342dadbabd9c8bac54d097506d11b
|
|
| MD5 |
833d5c34affa22bb432c95ee6bd45505
|
|
| BLAKE2b-256 |
cd03441edd8bdfa516536ce817173cb996f613bedefe380ae0bed6f0df5dcf6a
|