Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Read, create, merge, split, watermark, encrypt, OCR, and fill PDF files using Python and CLI tools
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
scripts/convert_pdf_to_images.py
1import os2import sys34from pdf2image import convert_from_path56789def convert(pdf_path, output_dir, max_dim=1000):10images = convert_from_path(pdf_path, dpi=200)1112for i, image in enumerate(images):13width, height = image.size14if width > max_dim or height > max_dim:15scale_factor = min(max_dim / width, max_dim / height)16new_width = int(width * scale_factor)17new_height = int(height * scale_factor)18image = image.resize((new_width, new_height))1920image_path = os.path.join(output_dir, f"page_{i+1}.png")21image.save(image_path)22print(f"Saved page {i+1} as {image_path} (size: {image.size})")2324print(f"Converted {len(images)} pages to PNG images")252627if __name__ == "__main__":28if len(sys.argv) != 3:29print("Usage: convert_pdf_to_images.py [input pdf] [output directory]")30sys.exit(1)31pdf_path = sys.argv[1]32output_directory = sys.argv[2]33convert(pdf_path, output_directory)34