Skip to content

Bug & Feature(Demerge_pdfs): Fix crash on empty hardcoded PDF, PyPDF2 deprecations, and add multi-mode splitting & CLI #527

Description

@Prayas340

Description

The Demerge_pdfs/demerging_pdfs.py script currently suffers from multiple critical bugs, legacy library incompatibilities, and logic limitations:

  1. Crash on Run (Hardcoded 0-byte PDF): Line 12 hardcodes merged_pdf = open('Python.pdf', mode='rb'). In the repository, Python.pdf is an empty 0-byte file, causing an immediate PdfReadError / EmptyFileError upon running.
  2. PyPDF2 Deprecations: Outdated classes (PyPDF2.PdfFileReader, PyPDF2.PdfFileWriter) and methods (numPages, getPage(), addPage()) cause deprecation warnings and incompatibilities with modern pypdf and PyPDF2 (v3.0+).
  3. Flawed Loop & Limit Check: The counter u += ctr is updated prior to verifying bounds, causing the program to print Limit exceeded! and abruptly terminate via break without recovery, leaving the remainder of the document unprocessed.
  4. Missing Splitting Features & CLI: Missing equal-chunk splitting, page range extraction (e.g. 1-5, 8, 10-12), burst splitting (1 page per file), and command-line argument support (argparse).
  5. Documentation Typo & Missing Files: README.md contains a typo in the run command (demerging_pdf.py), with missing requirements.txt and automated unit tests.

Type of issue

  • Feature (New Script / Enhancements)
  • Bug
  • Documentation

Checklist:

  • I have read the project guidelines.
  • I have checked previous issues to avoid duplicates.
  • This issue will be meaningful for the project.
  • I have added steps to reproduce the bug
  • I have proposed a possible solution for the bug

Steps to Reproduce:

  1. Open a terminal in Demerge_pdfs.
  2. Run python demerging_pdfs.py.
  3. The program attempts to open the empty 0-byte Python.pdf and crashes.
  4. If a user provides an input exceeding remaining pages, the program abruptly terminates without creating the file.

Proposed Solution:

  • Create a multi-version PDF adapter supporting pypdf and PyPDF2 (v3+ and legacy).
  • Add interactive input validation, remaining page tracker, and bounds checking.
  • Implement 4 split modes: Custom Interactive, Equal Page Chunks, Page Ranges, and Burst Mode.
  • Add full CLI argument parsing via argparse.
  • Add requirements.txt and automated unit tests in test_demerging_pdfs.py.
  • Fix documentation typo and update README.md.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions