Task Objective
- This Skill is used to: convert each page of a PDF file into an independent image file
- Capabilities include: PDF file parsing, image format conversion (PNG/JPG), adjustable resolution output
- Trigger conditions: scenarios where the user needs to convert PDF to images, extract PDF pages, convert PDF content to images, etc.
Prerequisites
- Dependency description: the dependency packages and versions required by the scripts
pymupdf>=1.23.0
Operation Steps
- Standard process:
- Prepare the PDF file
- Confirm the PDF file path (use
./to indicate the current working directory) - For example:
./document.pdf
- Confirm the PDF file path (use
- Prepare the PDF file
-
Execute the conversion
- Call the script to convert each page of the PDF file into an image
- Command example:
python scripts/convert_pdf_to_images.py \ --input ./document.pdf \ --output-dir ./images - Optional parameters:
--image-format: image format, supportspngorjpg, default ispng--dpi: image resolution (DPI), default is200--zip: generate a ZIP archive--zip-output: ZIP archive output path (default: images.zip)
-
View the output
- Image files are saved in the specified output directory
- File naming format:
page_001.png、page_002.png... - You can choose whether to generate a ZIP archive
Resource Index
- Required script: see scripts/convert_pdf_to_images.py(Purpose and parameters: PDF to image script)
Notes
- The input PDF file must exist and be readable
- The output directory must have write permission
- PDF page limit: currently supports PDF files within 100 pages; for more than 100 pages, please split before converting
- Converting large PDF files may take a long time, please wait patiently
Troubleshooting
- Script not found error: make sure to execute in the Skill directory, or use the relative path
scripts/xxx.py - Python version issue: make sure to use Python 3.6 or higher
- Missing dependencies: execute
pip install pymupdf>=1.23.0to install dependencies - Page count exceeded error: the PDF file exceeds 100 pages, please use a PDF tool to split it into multiple smaller files
Usage Examples
Example 1: Basic conversion (PNG format)
python scripts/convert_pdf_to_images.py \
--input ./report.pdf \
--output-dir ./images
Example 2: Use JPG format
python scripts/convert_pdf_to_images.py \
--input ./document.pdf \
--output-dir ./images \
--image-format jpg
Example 3: High-resolution output
python scripts/convert_pdf_to_images.py \
--input ./document.pdf \
--output-dir ./images \
--dpi 300
Example 4: Generate a ZIP archive
python scripts/convert_pdf_to_images.py \
--input ./document.pdf \
--output-dir ./images \
--zip \
--zip-output ./images.zip
Example 5: Full configuration
python scripts/convert_pdf_to_images.py \
--input ./report.pdf \
--output-dir ./images \
--image-format jpg \
--dpi 200 \
--zip