Skip to content

iSams123/pdf_basic_tools

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

PDF Toolkit

A comprehensive utility for working with PDF files, combining functionality to:

  1. Remove PDF restrictions (when you know the user password)
  2. Extract high-quality original images from PDFs

Features

PDF Handling

  • 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)

Image Extraction

  • 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

User Interface

  • Interactive command-line mode with menu-driven interface
  • Non-interactive mode for scripting and batch processing
  • Configurable output directories
  • Detailed status reporting

Installation

  1. Ensure you have Python 3.6+ installed
  2. Install required dependencies:
pip install -r requirements.txt

Usage

Interactive Mode

Run the script with no arguments for interactive mode:

python pdf_toolkit_v2.py

This will present you with a menu-driven interface where you can:

  • Open PDF files
  • Remove restrictions
  • Extract images
  • View PDF information
  • Configure settings

Command-Line Mode

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

Command-Line Arguments

  • -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.

Workflow Examples

Example 1: Process a Protected PDF

  1. Remove restrictions:

    python pdf_toolkit_v2.py --pdf protected.pdf --password userpass --unrestrict
  2. 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

Example 2: Interactive Session

$ 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

Dependencies

  • pikepdf: For PDF restriction removal
  • PyMuPDF: For PDF parsing and image extraction
  • tqdm: For progress bar display

Notes

  • 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.

About

A simple Python script for performing various PDF operations, including restriction removal and image extraction.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages