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.
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 (defaultkogo-diff)--dpi— rendering resolution for the visual diff, 96–180 (default 144)--sensitivity—high,standard, orlow(defaultstandard)--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 serveand 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_MBis enforced while reading each upload, but a client that sends a large body without aContent-Lengthheader (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. nginxclient_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:
- Mozilla PDF.js (Apache-2.0)
- PyMuPDF (AGPL-3.0-or-commercial)
- OpenCV (Apache-2.0)
- FastAPI (MIT)
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kogo-0.1.4.tar.gz.
File metadata
- Download URL: kogo-0.1.4.tar.gz
- Upload date:
- Size: 65.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
05c2bdaf8fc7e0ab2413b3cb1ae25c794fb0bf4b52c2bdd0e30eb7dc6527c1c8
|
|
| MD5 |
655079f4d590043dfb488040d1538aeb
|
|
| BLAKE2b-256 |
e39555d75d7d0c1a4ed44de4d3ed6dab9a3e5ac5caf1f68a0e4e0f6d34d232ea
|
Provenance
The following attestation bundles were made for kogo-0.1.4.tar.gz:
Publisher:
publish.yml on ta-061/kogo
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kogo-0.1.4.tar.gz -
Subject digest:
05c2bdaf8fc7e0ab2413b3cb1ae25c794fb0bf4b52c2bdd0e30eb7dc6527c1c8 - Sigstore transparency entry: 2567376046
- Sigstore integration time:
-
Permalink:
ta-061/kogo@8eff8ae9eee5b2d73a440c3bfcb8d220c3f4f006 -
Branch / Tag:
refs/tags/v0.1.4 - Owner: https://github.com/ta-061
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8eff8ae9eee5b2d73a440c3bfcb8d220c3f4f006 -
Trigger Event:
release
-
Statement type:
File details
Details for the file kogo-0.1.4-py3-none-any.whl.
File metadata
- Download URL: kogo-0.1.4-py3-none-any.whl
- Upload date:
- Size: 60.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4f0b06c39043ad51343087adc647f28ecfc36a3a2e65364f5040183dc81ff097
|
|
| MD5 |
41b8a0236d82fd10bf09cc858931468d
|
|
| BLAKE2b-256 |
6838872b7f142b22f99472d658ddc5d51e41bedada299d5c4325a6414e81efaf
|
Provenance
The following attestation bundles were made for kogo-0.1.4-py3-none-any.whl:
Publisher:
publish.yml on ta-061/kogo
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kogo-0.1.4-py3-none-any.whl -
Subject digest:
4f0b06c39043ad51343087adc647f28ecfc36a3a2e65364f5040183dc81ff097 - Sigstore transparency entry: 2567376748
- Sigstore integration time:
-
Permalink:
ta-061/kogo@8eff8ae9eee5b2d73a440c3bfcb8d220c3f4f006 -
Branch / Tag:
refs/tags/v0.1.4 - Owner: https://github.com/ta-061
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8eff8ae9eee5b2d73a440c3bfcb8d220c3f4f006 -
Trigger Event:
release
-
Statement type: