pdf-to-image-preview

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

PDF转图片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

  • 标准流程:
    1. 准备PDF文件
      • 确认PDF文件路径(使用
        ./
        表示当前工作目录)
      • 例如:
        ./document.pdf
    2. 执行转换
      • 调用脚本将PDF文件的每一页转换为图片
      • 命令示例:
        bash
        python scripts/convert_pdf_to_images.py \
          --input ./document.pdf \
          --output-dir ./images
      • 可选参数:
        • --image-format
          : 图片格式,支持
          png
          jpg
          ,默认为
          png
        • --dpi
          : 图片分辨率(DPI),默认为
          200
        • --zip
          : 生成ZIP压缩包
        • --zip-output
          : ZIP压缩包输出路径(默认:images.zip)
    3. 查看输出
      • 图片文件保存在指定的输出目录中
      • 文件命名格式:
        page_001.png
        page_002.png
        ...
      • 可选择是否生成ZIP压缩包
  • Standard Process:
    1. Prepare PDF File
      • Confirm the PDF file path (use
        ./
        to represent the current working directory)
      • Example:
        ./document.pdf
    2. 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
          : Image format, supports
          png
          or
          jpg
          , default is
          png
        • --dpi
          : Image resolution (DPI), default is
          200
        • --zip
          : Generate a ZIP compressed package
        • --zip-output
          : ZIP package output path (default: images.zip)
    3. 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
    pip install pymupdf>=1.23.0
    to install dependencies
  • 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 ./images
bash
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 jpg
bash
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 300
bash
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.zip
bash
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 \
  --zip
bash
python scripts/convert_pdf_to_images.py \
  --input ./report.pdf \
  --output-dir ./images \
  --image-format jpg \
  --dpi 200 \
  --zip