# Redwings PDF Tools: desktop PDF compressor and toolkit

> Visa documents must fit strict upload limits. This desktop tool compresses PDFs with several modes and uses a binary search to find the sharpest output under a target size.

URL: https://thuyavan.netlify.app/projects/redwings-pdf-tools
Updated: 2026-10-12

- Role: Solo: engine, GUI and packaging
- Period: 2026-07
- Technologies: Python, PDF & document generation, Desktop GUI (Tk / Qt), SQLite

## Summary

The engine analyses each PDF (text vs scanned, bitonal suitability, DPI) and chooses or applies a compression strategy:

Tier A lossless (pikepdf optimise)

Tier B image downsample / re-encode (PyMuPDF, optional Ghostscript)

Tier C bitonal 1-bit (CCITT / PNG) for text scans

MRC two-layer mixed raster content (ABBYY-style)

Modes are precision (Adobe-like, text-safe), balanced (Wondershare-like), maximum (ABBYY-like) and auto. Strength is level 1–5, a quality override, or a target size, which triggers a binary search for the sharpest result under the limit. Groups escalate compression across files until the bundle fits. Every version is kept with an “under target” badge. Results, recent files, sessions and templates are stored in SQLite. The UI was built first in Tkinter (themed, light / dark) and then ported to PySide6 (Qt) with background workers, a cancel / stop button and timers.

## Stack

PyMuPDF 1.28, pikepdf 10.10, pypdf 6.14, Pillow 12.3, PySide6 6.11, Tkinter / ttk (legacy UI), SQLite (db.py), optional Ghostscript (gswin64c), PyInstaller (RedwingsPDFTools.spec, build_exe.cmd, app icon), pyright config, headless engine smoke test.

## Architecture

app/
├─ config.py (colours, fonts, paths, MODE / LEVEL tables) · theme.py · utils.py · models.py (CompressionSettings, DocFile, Group, Template) · db.py · logging_setup.py · templates_def.py
├─ engine/ detect (capabilities) · analyze (text / scan / DPI, auto mode) · pdf_ops (shuffle / merge / split / rotate / reorder)
│ tier_lossless · tier_image · tier_bitonal · tier_mrc · render · compress (orchestrator + target search) · pipeline (group escalation) · cancel
├─ qt/ main_window, compressor_page (794), template_page (689), tools_pages, settings_page, preview_dialog, template_editor_dialog, widgets, flowlayout, workers (QThread), theme, dialogs
└─ ui/ (Tkinter) app, compressor_view, template_view, preview, merge / shuffle / split views, filelist, widgets

## Algorithm: target-size search

lo, hi = quality bounds; best = None; while lo ≤ hi: q = mid; out = compress(q); if size(out) ≤ target: best = out; lo = q + 1 else hi = q − 1 → if no result fits, escalate the tier (image → bitonal → MRC) and, for groups, compress the largest contributors further.

## Resume Bullet

Built a PySide6 desktop PDF toolkit with an adaptive multi-tier compression engine (lossless, image, bitonal, MRC) and target-size binary search, packaged with PyInstaller for a visa agency.
