pdf-to-image-preview
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePDF转图片Skill
PDF to Image Skill
任务目标
Task Objectives
- 本Skill用于:将PDF文件的每一页转换为独立的图片文件
- 能力包含:PDF文件解析、图片格式转换(PNG/JPG)、可调分辨率输出
- 触发条件:用户需要将PDF转换为图片、提取PDF页面、图片化PDF内容等场景
- This Skill is used to: Convert each page of a PDF file into independent image files
- Capabilities include: PDF file parsing, image format conversion (PNG/JPG), adjustable resolution output
- Trigger scenarios: When users need to convert PDFs to images, extract PDF pages, image-ify PDF content, etc.
前置准备
Prerequisites
- 依赖说明:scripts脚本所需的依赖包及版本
pymupdf>=1.23.0
- Dependency Notes: Required dependency packages and versions for the scripts
pymupdf>=1.23.0
操作步骤
Operation Steps
- 标准流程:
-
准备PDF文件
- 确认PDF文件路径(使用 表示当前工作目录)
./ - 例如:
./document.pdf
- 确认PDF文件路径(使用
-
执行转换
- 调用脚本将PDF文件的每一页转换为图片
- 命令示例:
bash
python scripts/convert_pdf_to_images.py \ --input ./document.pdf \ --output-dir ./images - 可选参数:
- : 图片格式,支持
--image-format或png,默认为jpgpng - : 图片分辨率(DPI),默认为
--dpi200 - : 生成ZIP压缩包
--zip - : ZIP压缩包输出路径(默认:images.zip)
--zip-output
-
查看输出
- 图片文件保存在指定的输出目录中
- 文件命名格式:、
page_001.png...page_002.png - 可选择是否生成ZIP压缩包
-
- Standard Process:
-
Prepare PDF File
- Confirm the PDF file path (use to represent the current working directory)
./ - Example:
./document.pdf
- Confirm the PDF file path (use
-
Execute Conversion
- Call the script to convert each page of the PDF file into images
- Command example:
bash
python scripts/convert_pdf_to_images.py \ --input ./document.pdf \ --output-dir ./images - Optional parameters:
- : Image format, supports
--image-formatorpng, default isjpgpng - : Image resolution (DPI), default is
--dpi200 - : Generate a ZIP compressed package
--zip - : ZIP package output path (default: images.zip)
--zip-output
-
View Output
- Image files are saved in the specified output directory
- File naming format: ,
page_001.png...page_002.png - Option to generate a ZIP compressed package
-
资源索引
Resource Index
- 必要脚本:见 scripts/convert_pdf_to_images.py(用途与参数:PDF转图片脚本)
- Required Script: See scripts/convert_pdf_to_images.py (Purpose & Parameters: PDF to Image conversion script)
注意事项
Notes
- 输入PDF文件必须存在且可读
- 输出目录必须具有写入权限
- PDF页数限制:暂支持100页以内的PDF文件,超过100页请拆分后转换
- 大型PDF文件转换可能需要较长时间,请耐心等待
- The input PDF file must exist and be readable
- The output directory must have write permissions
- PDF Page Limit: Currently supports PDF files with up to 100 pages. For files exceeding 100 pages, please split them before conversion
- Converting large PDF files may take a long time, please be patient
故障排查
Troubleshooting
- 脚本找不到错误:确保在Skill目录下执行,或使用相对路径
scripts/xxx.py - Python版本问题:确保使用Python 3.6或更高版本
- 依赖缺失:执行 安装依赖
pip install pymupdf>=1.23.0 - 页数超限错误:PDF文件超过100页,请使用PDF工具拆分为多个小文件
- Script Not Found Error: Ensure execution is in the Skill directory, or use the relative path
scripts/xxx.py - Python Version Issue: Ensure Python 3.6 or higher is used
- Missing Dependencies: Execute to install dependencies
pip install pymupdf>=1.23.0 - Page Limit Exceeded Error: If the PDF file has more than 100 pages, use a PDF tool to split it into smaller files
使用示例
Usage Examples
示例1:基本转换(PNG格式)
Example 1: Basic Conversion (PNG Format)
bash
python scripts/convert_pdf_to_images.py \
--input ./report.pdf \
--output-dir ./imagesbash
python scripts/convert_pdf_to_images.py \
--input ./report.pdf \
--output-dir ./images示例2:使用JPG格式
Example 2: Using JPG Format
bash
python scripts/convert_pdf_to_images.py \
--input ./document.pdf \
--output-dir ./images \
--image-format jpgbash
python scripts/convert_pdf_to_images.py \
--input ./document.pdf \
--output-dir ./images \
--image-format jpg示例3:高分辨率输出
Example 3: High-Resolution Output
bash
python scripts/convert_pdf_to_images.py \
--input ./document.pdf \
--output-dir ./images \
--dpi 300bash
python scripts/convert_pdf_to_images.py \
--input ./document.pdf \
--output-dir ./images \
--dpi 300示例4:生成ZIP压缩包
Example 4: Generate ZIP Compressed Package
bash
python scripts/convert_pdf_to_images.py \
--input ./document.pdf \
--output-dir ./images \
--zip \
--zip-output ./images.zipbash
python scripts/convert_pdf_to_images.py \
--input ./document.pdf \
--output-dir ./images \
--zip \
--zip-output ./images.zip示例5:完整配置
Example 5: Full Configuration
bash
python scripts/convert_pdf_to_images.py \
--input ./report.pdf \
--output-dir ./images \
--image-format jpg \
--dpi 200 \
--zipbash
python scripts/convert_pdf_to_images.py \
--input ./report.pdf \
--output-dir ./images \
--image-format jpg \
--dpi 200 \
--zip