# 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.

URL: https://thuyavan.netlify.app/projects/pdf-agent-tool
Updated: 2026-10-12

- Period: 2026-05
- Technologies: Python, PDF & document generation, Desktop GUI (Tk / Qt)

## 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



## 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.
