Skip to content

refactor: replace deprecated PyPDF2 with pypdf - #480

Open
denis-samatov wants to merge 2 commits into
VectifyAI:mainfrom
denis-samatov:fix/replace-deprecated-pypdf2
Open

refactor: replace deprecated PyPDF2 with pypdf#480
denis-samatov wants to merge 2 commits into
VectifyAI:mainfrom
denis-samatov:fix/replace-deprecated-pypdf2

Conversation

@denis-samatov

Copy link
Copy Markdown

Summary

Changes

  1. Dependencies:
    • Replaced PyPDF2==3.0.1 / PyPDF2 = ">=3.0.0" with pypdf>=4.0.0 in requirements.txt and pyproject.toml.
  2. Core & Local API:
    • pageindex/utils.py: Replaced PyPDF2.PdfReader with pypdf.PdfReader for text extraction, token counting, and metadata extraction.
    • pageindex/local_api.py: Updated _extract_page_texts to use pypdf.PdfReader.
  3. Flash Parser (parser_pdfium_charlevel & parser_pdfium_parallel):
    • Updated _PdfDoc and internal generic AST imports from PyPDF2.generic to pypdf.generic.
    • Updated worker and pipeline readers to use pypdf.PdfReader.
  4. Tests:

Verification

  • Ran full test suite via pytest:
    • 431 passed, 54 skipped, 0 errors, 0 failures.
    • Zero DeprecationWarning for PyPDF2.
  • Verified AES-encrypted PDF handling without DependencyError.

Closes #478
Closes #426

- Replace deprecated PyPDF2 (unmaintained since 2022) with pypdf >= 4.0.0
- Update core PDF extraction, metadata readers, and token counters
- Update Flash parser_pdfium_charlevel adapter and parallel worker
- Keep backwards-compatible alias for pdf_parser='PyPDF2' in get_page_tokens
- Fix DependencyError crash on AES permission-only encrypted PDFs
- Update test suite and add regression test for AES-encrypted PDFs

Closes VectifyAI#478
Closes VectifyAI#426

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 00bdd03844

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread pyproject.toml Outdated
openai-agents = ">=0.18.1"
litellm = ">=1.97.0"
PyPDF2 = ">=3.0.0"
pypdf = ">=4.0.0"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Install pypdf's crypto extra for AES documents

On a clean pageindex installation, pypdf does not include its optional AES backend, so opening the permission-only AES PDFs described in #426 can still raise DependencyError; depend on the crypto extra in both package manifests. The new regression test does not expose this because PdfWriter.encrypt(..., algorithm=None) defaults to RC4 rather than AES, despite the test name and docstring.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Updated pyproject.toml and requirements.txt to require pypdf[crypto], and parametrized test_permission_only_encrypted_pdf_does_not_crash_on_aes to explicitly test both AES-128 and AES-256 encryption algorithms.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant