PDF Agent: PDF split and shuffle tool (4 versions)
A desktop helper to split and shuffle PDF pages when preparing visa documents. It went from a first Tkinter prototype to a bug-fixed build in about a week of May 2026.
- Period
- May 2026
- Technologies
- 3
- Diagrams
- 1
- Reading time
- 1 min
Purpose
A single-file desktop helper to split PDFs in several ways for visa-document preparation (e.g. splitting a long bank statement into portal-sized parts, or creating randomised page groups), running work on a background thread so the Tk UI stays responsive.
Version History
| Version | Date | LOC | Functions | What changed |
|---|---|---|---|---|
pdf_agent.py |
05-13 | 993 | 50 | Baseline GUI + core split / shuffle operations |
pdf_agent_2.py |
05-19 | 1,751 | 74 | Big expansion: class-based app (__init__, _build_content), file browser, task chaining (_chain_task, _run_task, _on_done), error display / clearing, option and distribution change handlers, input validation (_validate_and_get_ranges), page counting (get_pdf_page_count), and new split strategies: calculate_split_ranges_by_n, calculate_split_ranges_after_pages (+ _split_after_indices_to_ranges), calculate_split_ranges_by_type, calculate_random_n_files_split, calculate_random_auto_split |
pdf_agent_fixed.py |
05-19 | 1,373 | 80 | Refactored / fixed rewrite: more helper functions, leaner than v2; fixes from v2 testing |
pdf_agent_fixed_2.py |
05-19 | 1,373 | 80 | Identical to fixed except button foreground colours (#ffffff → #cccccc for primary / success / warning styles): a theme tweak |
Latest / best: pdf_agent_fixed.py (or _fixed_2 for the dimmer button style). These scripts were superseded by P19 in July 2026. |
How it works
Diagram as text
flowchart TD
A[Browse PDF] --> B[get_pdf_page_count]
B --> C{split strategy}
C --> C1[by N parts]
C --> C2[after given pages]
C --> C3[by type]
C --> C4[random N files]
C --> C5[random auto]
C1 & C2 & C3 & C4 & C5 --> V[_validate_and_get_ranges]
V --> T[_run_task on worker thread → write parts]
T --> D[_on_done: status / errors in UI]Techniques
Range arithmetic over page indices; randomised partitioning (random) for shuffled bundles; Tkinter custom-styled buttons (style → colour maps); background threads with UI-safe completion callbacks.
Related projects
Redwings PDF Tools: desktop PDF compressor and toolkit
A desktop PDF compressor with a binary search for the sharpest result under a size limit.
PythonPDF & document generationDesktop GUI (Tk / Qt)SQLiteBulk test-document generator and Stitch-to-PDF storyboard
Python scripts that batch-generate numbered test documents (Word to PDF, Pillow images) plus a Stitch-to-PDF storyboard for QA and design review.
PythonPDF & document generationcopyCode prototypes: 15 versions towards ThuOneCopy
Fifteen PyQt5 prototype versions of a tool that copies selected project files as one block for ChatGPT, evolving into ThuOneCopy.
PythonDesktop GUI (Tk / Qt)Want to discuss this project?
Happy to walk through the architecture, trade-offs or the code.