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

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
KOGO_VENDOR_DIR ~/.local/share/kogo/vendor/pdfjs Where kogo fetch-viewer installs (and the server looks for) the local PDF.js viewer assets

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

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 is where self-hosters should point to their source.

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.2.tar.gz (60.3 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.2-py3-none-any.whl (56.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: kogo-0.1.2.tar.gz
  • Upload date:
  • Size: 60.3 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.2.tar.gz
Algorithm Hash digest
SHA256 2d2cc07cbb7e613c1bbea9aab0e272bc54750249ed0da94193ee64053c5f52f6
MD5 9c75adc14aa0e7fda930bbd806e3ed85
BLAKE2b-256 1ba777e8485d6b02298345460985dd0c0b8c8cf9e949217d00c46e4b070511f8

See more details on using hashes here.

Provenance

The following attestation bundles were made for kogo-0.1.2.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.2-py3-none-any.whl.

File metadata

  • Download URL: kogo-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 56.6 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 cc77152c153538e38b3334dc65408cfea8556213dca6e76b6572c6fe83ee9dec
MD5 c5b9669c4ffb86164c16645a4488adb4
BLAKE2b-256 549370438ccf9678bb78d2612a491a248695605731493c61fa311d3b9ebd47a4

See more details on using hashes here.

Provenance

The following attestation bundles were made for kogo-0.1.2-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

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

This release

0.1.2 This release

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