Skip to main content

kogo

Layout-aware PDF diff for revisions — compare an old and new PDF and highlight added or deleted text, figures, and annotations, in the browser and in marked PDFs.

kogo (校合) is the Japanese publishing term for checking a revision against the original.

kogo results

Website: https://portfolio.tatu-sec.dev/kogo/

Features

  • Word-level text diff for Latin text, character-level precision for CJK (Chinese, Japanese, Korean) text, including rare kanji across CJK Extensions B-J
  • Reading order reconstructed from whitespace layout, so multi-column pages and slide-style text boxes are compared correctly instead of interleaved
  • Page alignment that tolerates inserted or removed pages, using both text and visual page signatures
  • Visual diff for figures, equations, and layout, with text areas masked out and scanner/export shift registration for image-only pages
  • Detects added or removed highlights, comments, and ink annotations
  • Detects style-only changes (bold, italic, font-size) on otherwise-unchanged text, marked in amber
  • Markers are baked into the output PDFs so they show up in any viewer, even with annotations hidden
  • Selectable-text web preview powered by Mozilla PDF.js
  • Downloadable old-highlighted, new-highlighted, and side-by-side comparison PDFs
  • All processing happens locally — nothing is sent to an external service

Quick start

CLI only

pip install kogo
kogo diff old.pdf new.pdf -o out/

Web app

pip install "kogo[serve]"
kogo fetch-viewer
kogo serve

kogo fetch-viewer downloads the local PDF.js viewer assets used by the web preview (see Configuration); it's not needed with Docker, which bundles them in the image.

Then open http://127.0.0.1:8080.

Docker

docker compose up -d --build

Then open http://localhost:8080. By default the container only binds to 127.0.0.1 (localhost). To share it on a LAN, there is no authentication built in, so only do this on a trusted network:

KOGO_HOST=0.0.0.0 docker compose up -d --build

docker-compose.yml sets mem_limit: 2g, cpus: 2, and pids_limit: 256 as a backstop, since PyMuPDF and OpenCV are native-code parsers processing untrusted PDFs. Raise these if legitimate large comparisons get OOM-killed or throttled. Equivalent docker run flags: --memory=2g --cpus=2 --pids-limit=256.

CLI usage

kogo diff OLD.pdf NEW.pdf \
  -o kogo-diff \
  --dpi 144 \
  --sensitivity standard \
  --max-pages 200

Options:

  • -o, --out — output directory (default kogo-diff)
  • --dpi — rendering resolution for the visual diff, 96–180 (default 144)
  • --sensitivityhigh, standard, or low (default standard)
  • --max-pages — maximum pages per file (default 200)
  • --no-previews — skip generating page preview images
  • --json — print the full result as JSON

kogo serve runs the web application:

kogo serve --host 127.0.0.1 --port 8080

Use as a library

The diff engine is a regular Python API — pip install kogo is enough (no web dependencies needed):

import kogo

result = kogo.compare_pdfs("old.pdf", "new.pdf", "out/")
print(result["summary"])
# out/ now contains old-highlighted.pdf, new-highlighted.pdf,
# side-by-side.pdf, result.json, and page previews.

kogo.compare_pdfs raises kogo.ComparisonError for user-facing problems (encrypted, empty, oversized, or unreadable PDFs). Keyword options mirror the CLI: dpi, sensitivity, max_pages, previews, old_name, new_name.

Configuration

The web app reads these environment variables:

Variable Default Description
JOBS_DIR ~/.local/share/kogo/jobs Where uploaded files and comparison results are stored
MAX_UPLOAD_MB 100 Maximum size per uploaded PDF
MAX_PAGES 200 Maximum pages per PDF
JOB_TTL_HOURS 24 How long comparison results are kept before cleanup
MAX_CONCURRENT_JOBS 2 Number of comparisons processed at once
JOB_TIMEOUT_SECONDS 900 Wall-clock limit for a single comparison before it's aborted (minimum 60)
KOGO_VENDOR_DIR ~/.local/share/kogo/vendor/pdfjs Where kogo fetch-viewer installs (and the server looks for) the local PDF.js viewer assets
KOGO_SOURCE_URL https://github.com/ta-061/kogo Source code link shown in the web app footer and the kogo serve startup banner — see License

How it works

Text is extracted at word precision (character precision for CJK) and reordered using recursive whitespace cuts, so columns, slide text boxes, and reflowed paragraphs are read in a sensible order rather than the PDF's raw internal stream order. Pages are aligned across the two documents with a similarity-based sequence alignment (combining text and, for image-heavy pages, visual signatures) so inserted or removed pages don't desynchronize the rest of the comparison. Remaining differences are then diffed with Python's difflib.

Figures, equations, and other non-text layout are compared by rendering each page to an image, masking out the areas already covered by the text diff, and taking a pixel difference. Image-only pages get a small registration step to correct for scanner or export shifts before the pixel diff runs. Existing PDF annotations (highlights, comments, ink) are fingerprinted and diffed separately.

Limitations

  • Scan-only PDFs (no embedded text layer) are compared visually; add an OCR text layer first if you need word-level text diffs
  • Password-protected PDFs are not supported
  • Complex tables and vertical text layouts may need a visual check in addition to the automated diff
  • There is no authentication built in. kogo serve and the default Docker Compose setup only bind to localhost; put the web app behind a reverse proxy with authentication before exposing it to anything beyond your local machine or trusted LAN
  • MAX_UPLOAD_MB is enforced while reading each upload, but a client that sends a large body without a Content-Length header (chunked transfer) is only caught by that same streaming check, not rejected up front; a reverse proxy in front of kogo should also set its own body-size limit (e.g. nginx client_max_body_size) for defense in depth

Development

python -m unittest discover -s tests -v

License

kogo is licensed under AGPL-3.0. See LICENSE.

Copyright (C) 2026 ta-061. Released under the GNU Affero General Public License v3.0 (AGPL-3.0-only).

PyMuPDF (and the underlying MuPDF library) is distributed under AGPL-3.0-or-commercial; check its license terms before redistributing kogo or offering it as a network service.

If you modify kogo and let others use it over a network (for example, by self-hosting a modified version of the web app), AGPL-3.0 §13 requires you to offer those users the corresponding source code. The "Source code" link in the web app's footer and the kogo serve startup banner both read from the KOGO_SOURCE_URL environment variable (default: this repository) — operators running a modified build must set it to their own fork's repository to satisfy §13.

Credits:

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kogo-0.1.5.tar.gz (66.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kogo-0.1.5-py3-none-any.whl (67.4 kB view details)

Uploaded Python 3

File details

Details for the file kogo-0.1.5.tar.gz.

File metadata

  • Download URL: kogo-0.1.5.tar.gz
  • Upload date:
  • Size: 66.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for kogo-0.1.5.tar.gz
Algorithm Hash digest
SHA256 2348810f682f20eb82f928dbef1521b6669c63b22552f1f1ce119dbdc73ea9db
MD5 d5d522849180796d2537d293d2490cef
BLAKE2b-256 b4c6222f1e01075b6940fab053345affebde5ca55249f7286bf07407c21e7245

See more details on using hashes here.

Provenance

The following attestation bundles were made for kogo-0.1.5.tar.gz:

Publisher: publish.yml on ta-061/kogo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file kogo-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: kogo-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 67.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for kogo-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 b1ab6c4a81165e78f6248c87ff329097df1bff218f3b93e465b1b0e06b6891bd
MD5 e3f2b62e23257c0cc3b4f8cd5b63407f
BLAKE2b-256 07ae09dd3f8ff52f3979821056d0aaf1d7fa793d210fb2e624bea1dcb9ba2db9

See more details on using hashes here.

Provenance

The following attestation bundles were made for kogo-0.1.5-py3-none-any.whl:

Publisher: publish.yml on ta-061/kogo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.1.7

2 files

0.1.6

2 files

This release

0.1.5 This release

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page