Description
The Demerge_pdfs/demerging_pdfs.py script currently suffers from multiple critical bugs, legacy library incompatibilities, and logic limitations:
- 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.
- 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+).
- 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.
- 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).
- 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
Checklist:
Steps to Reproduce:
- Open a terminal in
Demerge_pdfs.
- Run
python demerging_pdfs.py.
- The program attempts to open the empty 0-byte
Python.pdf and crashes.
- 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.
Description
The
Demerge_pdfs/demerging_pdfs.pyscript currently suffers from multiple critical bugs, legacy library incompatibilities, and logic limitations:merged_pdf = open('Python.pdf', mode='rb'). In the repository,Python.pdfis an empty 0-byte file, causing an immediatePdfReadError/EmptyFileErrorupon running.PyPDF2.PdfFileReader,PyPDF2.PdfFileWriter) and methods (numPages,getPage(),addPage()) cause deprecation warnings and incompatibilities with modernpypdfandPyPDF2(v3.0+).u += ctris updated prior to verifying bounds, causing the program to printLimit exceeded!and abruptly terminate viabreakwithout recovery, leaving the remainder of the document unprocessed.1-5, 8, 10-12), burst splitting (1 page per file), and command-line argument support (argparse).README.mdcontains a typo in the run command (demerging_pdf.py), with missingrequirements.txtand automated unit tests.Type of issue
Checklist:
Steps to Reproduce:
Demerge_pdfs.python demerging_pdfs.py.Python.pdfand crashes.Proposed Solution:
pypdfandPyPDF2(v3+ and legacy).argparse.requirements.txtand automated unit tests intest_demerging_pdfs.py.README.md.