Skip to content

Migrate from PyPDF2 to PyMuPDF - #24

Merged
fdb02983rhy merged 2 commits into
mainfrom
feat/migrate-pypdf2-to-pymupdf
Oct 30, 2025
Merged

Migrate from PyPDF2 to PyMuPDF#24
fdb02983rhy merged 2 commits into
mainfrom
feat/migrate-pypdf2-to-pymupdf

Conversation

@fdb02983rhy

@fdb02983rhy fdb02983rhy commented Oct 30, 2025

Copy link
Copy Markdown
Owner

Summary

Complete migration from PyPDF2 to PyMuPDF for improved performance, consistency, and better resource management across all PDF processing tools. Includes code quality improvements, CI automation, and version 1.0.0 release.

Changes

🔧 Dependency Updates

  • ❌ Removed PyPDF2 dependency entirely
  • ⬆️ PyMuPDF: 1.25.41.26.5
  • ⬆️ Pillow: 11.1.012.0.0
  • ⬆️ dify_plugin: 0.1.0-0.2.00.3.0-0.6.0

✨ Tool Improvements

pdf_page_counter.py

  • Migrated to PyMuPDF with proper resource cleanup
  • Removed output_format parameter (now always outputs both text and JSON)
  • Added dynamic padding for page numbers (supports 100+ page PDFs)
  • Improved error handling and validation

pdf_single_page_extractor.py

  • Migrated to PyMuPDF's insert_pdf() method
  • Added proper resource cleanup for doc and output objects
  • Fixed buffer position reset issue
  • Enhanced error handling in exception paths

pdf_multi_pages_extractor.py

  • Migrated to PyMuPDF with insert_pdf() for page extraction
  • Improved resource management with proper cleanup
  • Fixed buffer handling for PDF output
  • Enhanced error recovery

pdf_splitter.py

  • Migrated to PyMuPDF for page splitting
  • Added proper resource cleanup in loops
  • Improved error handling and memory management
  • Fixed buffer position reset

pdf_to_png.py

  • Enhanced existing PyMuPDF implementation
  • Added explicit filetype parameter
  • Improved resource cleanup with conditional checks
  • Added cleanup in exception handlers

📝 Documentation

  • Added MIT LICENSE with third-party license attribution (Apache-2.0, AGPL-3.0, MIT-CMU)
  • Added comprehensive TODO.md with complete migration checklist
  • Updated README.md:
    • Removed deprecated output_format parameter documentation
    • Added LICENSE section with third-party dependency information
    • Added PyMuPDF AGPL-3.0 licensing notice
  • Updated PRIVACY.md to remove specific library mentions
  • Removed library name references from user-facing descriptions
  • Added .difyignore entries for development files

⚙️ Configuration

  • Updated plugin version: 0.0.41.0.0 🎉
  • Updated manifest.yaml and provider configuration
  • Updated pdf_page_counter.yaml to remove output_format parameter
  • Cleaned up descriptions to be library-agnostic

🔍 Code Quality

  • Fixed linting issues identified by ruff:
    • Removed unused imports (ToolParameterOption, List)
    • Removed unused exception variables
  • Applied ruff formatter to all Python files
  • Applied mdformat to all markdown files (PRIVACY.md, README.md, TODO.md)

🚀 CI/CD

  • Added GitHub Actions workflow (.github/workflows/lint.yml):
    • Automated ruff linting checks
    • Automated ruff format verification
    • Automated mdformat markdown formatting checks
    • Runs on push to main and all pull requests

Test Plan

  • Test pdf_page_counter with various PDF sizes (1 page, multiple pages, 100+ pages)
  • Test pdf_single_page_extractor with edge cases (first, last, middle pages)
  • Test pdf_multi_pages_extractor with complex scenarios (ranges, duplicates, fixed+dynamic)
  • Test pdf_splitter with various PDF sizes
  • Verify all tools properly clean up resources
  • Verify error handling works correctly
  • Verify ruff linting passes
  • Verify code formatting is consistent
  • Verify markdown formatting is standardized

Breaking Changes

  • pdf_page_counter: Removed output_format parameter. Tool now always outputs both text and JSON formats.
  • Version: Major version bump to 1.0.0 indicating stable release with breaking changes

🤖 Generated with Claude Code

fdb02983rhy and others added 2 commits October 30, 2025 22:45
## Summary
- Complete migration from PyPDF2 to PyMuPDF for all PDF processing tools
- Add MIT license with third-party license attribution
- Add comprehensive migration TODO documentation
- Update dependencies and improve resource management

## Changes

### Dependency Updates
- Remove PyPDF2 dependency entirely
- Update PyMuPDF: 1.25.4 → 1.26.5
- Update Pillow: 11.1.0 → 12.0.0
- Update dify_plugin: 0.1.0-0.2.0 → 0.3.0-0.6.0

### Tool Improvements
All tools migrated with proper resource cleanup and error handling:

**pdf_page_counter.py**:
- Migrated to PyMuPDF with proper resource cleanup
- Removed output_format parameter (now always outputs both text and JSON)
- Added dynamic padding for page numbers (supports 100+ page PDFs)
- Improved error handling and validation

**pdf_single_page_extractor.py**:
- Migrated to PyMuPDF's insert_pdf() method
- Added proper resource cleanup for doc and output objects
- Fixed buffer position reset issue
- Enhanced error handling in exception paths

**pdf_multi_pages_extractor.py**:
- Migrated to PyMuPDF with insert_pdf() for page extraction
- Improved resource management with proper cleanup
- Fixed buffer handling for PDF output
- Enhanced error recovery

**pdf_splitter.py**:
- Migrated to PyMuPDF for page splitting
- Added proper resource cleanup in loops
- Improved error handling and memory management
- Fixed buffer position reset

**pdf_to_png.py**:
- Enhanced existing PyMuPDF implementation
- Added explicit filetype parameter
- Improved resource cleanup with conditional checks
- Added cleanup in exception handlers

### Documentation
- Added MIT LICENSE with third-party license attribution
- Added TODO.md with complete migration checklist
- Updated README.md to remove deprecated output_format parameter
- Added .difyignore entries for development files

### Configuration
- Updated manifest.yaml version: 0.0.3 → 0.0.4
- Updated pdf_page_counter.yaml to remove output_format parameter

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Run ruff linter and formatter to fix code quality issues
- Run mdformat to standardize markdown formatting
- Add LICENSE section to README with third-party dependency information
- Add GitHub Actions CI workflow for automated linting checks

Changes:
- Fixed unused imports and variables identified by ruff
- Formatted all Python files with ruff formatter
- Formatted all markdown files with mdformat --number
- Added lint.yml workflow: ruff check, ruff format, mdformat
- Updated README with MIT license and PyMuPDF AGPL-3.0 notice
- Updated .difyignore and .gitignore

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@fdb02983rhy
fdb02983rhy merged commit 8c4304b into main Oct 30, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant