2026-07-13 20:04:57 +02:00
2026-07-13 20:04:57 +02:00
2026-07-13 20:04:57 +02:00
2026-07-13 20:04:57 +02:00

Kramerius PDF Downloader

Download page images from Digitalniknihovna / Kramerius and assemble them into a PDF.

The script:

  • discovers all page UUIDs for a document
  • downloads each page image
  • embeds the downloaded JPEGs into a PDF
  • can resume interrupted downloads by skipping existing images
  • supports authenticated downloads with a Kramerius bearer token
  • can resolve other digitalniknihovna.cz/<library>/... links automatically

Requirements

Python 3.10 or newer is recommended. The script uses only the Python standard library, so no pip install step is needed.

Basic Usage

python3 download_kramerius_pdf.py "https://www.digitalniknihovna.cz/mzk/view/uuid:0abf59c0-794e-11e4-8ce5-005056827e52?page=uuid:e57e2820-8547-11e4-a321-5ef3fc9bb22f" \
  --output-dir pages \
  --pdf book.pdf

To test only the first few pages:

python3 download_kramerius_pdf.py "URL_HERE" \
  --limit 20 \
  --output-dir test_pages \
  --pdf test.pdf

If a run is interrupted, run the same command again. Existing images are skipped unless you pass --overwrite.

Authenticated Downloads

Some pages require a logged-in account. The Digitalniknihovna web app sends protected image requests with:

Authorization: Bearer <token>
Client: www.digitalniknihovna.cz

Use either --auth-token:

python3 download_kramerius_pdf.py "URL_HERE" \
  --auth-token "PASTE_TOKEN_HERE" \
  --output-dir pages \
  --pdf book.pdf

Or put the token in auth-token.txt and use --auth-file:

python3 download_kramerius_pdf.py "URL_HERE" \
  --auth-file auth-token.txt \
  --output-dir pages \
  --pdf book.pdf

auth-token.txt may contain either the raw token or a copied header like:

Authorization: Bearer eyJ...

How To Get The Auth Token

  1. Log in on https://www.digitalniknihovna.cz.
  2. Open the protected book page in the browser.
  3. Open browser developer tools:
    • Chrome / Edge: F12 or Ctrl+Shift+I
    • Firefox: F12
  4. Go to the Application tab.
  5. Open Local storage in the left sidebar.
  6. Select:
https://www.digitalniknihovna.cz
  1. Find the key for your library. For MZK it is:
auth.token.mzk
  1. Copy the value and save it in auth-token.txt, or pass it directly with --auth-token.

For another library, the key usually follows the same pattern:

auth.token.<library-code>

For example, a URL containing /mzk/view/... uses auth.token.mzk.

Using Other Digitalniknihovna URLs

Paste the document URL directly:

python3 download_kramerius_pdf.py "https://www.digitalniknihovna.cz/LIBRARY_CODE/view/uuid:..." \
  --auth-file auth-token.txt \
  --output-dir pages \
  --pdf book.pdf

The script reads the library code from the URL and tries to resolve the correct Kramerius API backend automatically. If that fails, pass the API backend manually:

python3 download_kramerius_pdf.py "URL_HERE" \
  --library mzk \
  --base-url "https://api.kramerius.mzk.cz" \
  --auth-file auth-token.txt \
  --output-dir pages \
  --pdf book.pdf

Useful Options

--limit N          Download only the first N pages
--overwrite        Redownload images that already exist
--delay SECONDS    Wait between image downloads
--cookies FILE     Send cookies from a cookies.txt export
--auth-token TOKEN Send Authorization: Bearer TOKEN
--auth-file FILE   Read token or headers from a file
--client VALUE     Override the Client header

Security Notes

Treat auth-token.txt, cookie-dl.txt, and copied request headers like passwords. Do not share them and do not commit them to version control.

This repository's .gitignore already ignores common token, cookie, header, PDF, and downloaded-page files.

S
Description
Kramerius / Digitalniknihovna downloader and PDF generator
Readme
35 KiB
Languages
Python 100%