A comprehensive utility for working with PDF files, combining functionality to:
- Remove PDF restrictions (when you know the user password)
- Extract high-quality original images from PDFs
- Open and analyze any PDF file
- Display detailed PDF information (metadata, encryption status, image counts)
- Remove restrictions from password-protected PDFs (requires knowing the user password)
- Extract all unique images in their original format
- Filter images by size
- Extract from specific page ranges
- Avoid duplicate extraction when the same image appears multiple times
- Progress tracking for large documents
- Interactive command-line mode with menu-driven interface
- Non-interactive mode for scripting and batch processing
- Configurable output directories
- Detailed status reporting
- Ensure you have Python 3.6+ installed
- Install required dependencies:
pip install -r requirements.txtRun the script with no arguments for interactive mode:
python pdf_toolkit_v2.pyThis will present you with a menu-driven interface where you can:
- Open PDF files
- Remove restrictions
- Extract images
- View PDF information
- Configure settings
For batch processing or scripting, use command-line arguments:
# Extract images from a PDF
python pdf_toolkit_v2.py --pdf document.pdf --extract --output ./images/
# Remove restrictions and then extract images
python pdf_toolkit_v2.py --pdf protected.pdf --password mypassword --unrestrict
# Show help
python pdf_toolkit_v2.py --help-i, --interactive: Run in interactive mode (default when no arguments provided)-p, --pdf PATH: Path to the PDF file--password PASSWORD: User password for restricted PDFs-u, --unrestrict: Remove PDF restrictions (requires --password)--unrestrict-output PATH: Output path for the unrestricted PDF when using --unrestrict.-e, --extract: Extract images from the PDF-o, --output DIR: Output directory for extracted images--pages RANGE: Page range for image extraction (e.g., '1-5,8,10-12'). Applies to --extract. 1-based indexing.--min-size WxH: Minimum image size filter (e.g., '100x100'). Applies to --extract. Images smaller than W or H are skipped.
-
Remove restrictions:
python pdf_toolkit_v2.py --pdf protected.pdf --password userpass --unrestrict
-
Then extract images:
python pdf_toolkit_v2.py --pdf protected_unrestricted.pdf --extract
Or combine both steps:
python pdf_toolkit_v2.py --pdf protected.pdf --password userpass --unrestrict --extract$ python pdf_toolkit_v2.py
==========================================
PDF TOOLKIT - Restriction Removal & Image Extraction
==========================================
CURRENT STATUS:
No PDF file currently loaded
Output Directory: Not set (will use PDF directory)
------------------------------------------------------------
AVAILABLE COMMANDS:
1. open - Open a PDF file
2. unrestrict - Remove PDF restrictions (requires password)
3. extract - Extract images from current PDF
4. info - Show detailed info about the current PDF
5. setup - Configure output directory
6. help - Show this help message
7. quit - Exit the program
Enter command: open
Enter path to PDF file: ./document.pdf
Successfully opened 'document.pdf'
Pages: 25
Encrypted: True
Password Required: True
This PDF requires a password. Use 'unrestrict' command to remove restrictions.
Enter command: unrestrict
Enter the user password for the PDF (or press Enter to cancel): mypassword
Enter output filename (or press Enter for default):
Attempting to remove restrictions from: document.pdf
Success! Saved unrestricted PDF to: ./document_unrestricted.pdf
Use this unrestricted version as current file? (y/n): y
Now using the unrestricted version.
Enter command: extract
Output directory [default: ./document_unrestricted_images]:
Extract from specific pages? (e.g., '1-5,8,10-12' or press Enter for all):
Minimum image size in pixels (e.g., '100x100' or press Enter for all): 100x100
Extracting images from 25 pages...
Processing pages: 100%|██████████████████████| 25/25 [00:03<00:00, 8.25pages/s]
Extraction complete. Total unique images extracted: 17
Images saved to: ./document_unrestricted_images
Enter command: quit
pikepdf: For PDF restriction removalPyMuPDF: For PDF parsing and image extractiontqdm: For progress bar display
- This tool respects copyright and is intended for legitimate use cases where you own the PDF and have the right to access its contents.
- Image extraction preserves the original image format and quality as stored in the PDF.
- The tool extracts each unique image only once, even if it appears multiple times in the document.