Skip to main content

dpsprep

Tests PyPI - Python Version PyPI - Version AUR Package

Convert DjVu files to PDF.

The name comes from Sony's Digital Paper System (DPS), for which the tool was initially developed - see below.

Table of contents

Also see the wiki.

Usage

Full example (the name of the PDF is optional and inferred from the input name):

dpsprep --pool=8 --quality=50 input.djvu output.pdf

If you have OCRmyPDF installed, you can use its PDF optimizer:

dpsprep -O3 input.djvu

You can also skip translating the text layer (it is sometimes not being translated well) and redo the OCR:

dpsprep --socr rus,eng,grc input.djvu

Rather than launching the ocrmypdf CLI, we use the API directly. The option --socr ("streamlined" OCR) used above is a shorthand for the following:

dpsprep --ocr '{"language": ["rus", "eng", "grc"]}' input.djvu

Sometimes the pages of scanned books are saved as colorful images. For PDF, saving bitonal page backgrounds as RGB images can inflate the file by an order of magnitude (see the notes on compression in the wiki). We try to infer the color mode of each page, however that is sometimes inefficient. In such cases, we can force the color mode as follows:

dpsprep --mode bitonal input.djvu start.pdf

In case we want to preserve the cover page as-is, we can use ranges:

dpsprep --mode bitonal[2-end] input.djvu start.pdf

For details on these and other options, as well as the allowed range syntax, consult the man page (included in the wheels, also avaiable online).

Installation

From PyPI

The dpsprep binary can be installed from the PyPI package via pipx:

pipx install dpsprep

An alternative is to use uv:

uv tool install dpsprep

The only hard prerequisite is djvulibre (e.g. djvulibre on Arch, libdjvulibre-dev on Ubuntu, etc.). We use the Python bindings from the package djvulibre-python (not to be confused with the unmaintained python-djvulibre; see this pull request).

Optional prerequisites are:

  • libtiff for bitonal image compression.
  • libjpeg (or libjpeg-turbo) for multitotal (RGB or grayscale) compression.
  • OCRmyPDF and jbig2enc for PDF optimization (see the next section).

libtiff depends on libjpeg, so installing libtiff will likely install both.

For details on how these dependencies can be installed, see the GitHub Actions test workflow and the AUR package.

As described in the notes on compression in the wiki, you might want to also include the compress extra:

pipx install dpsprep[compress]

Similarly, for OCR, the ocr extra must be used (coincidentally, both pull in the same package - OCRmyPDF).

If you intend to use this project programmatically (e.g. for a web UI), please contact us so that we can agree on a stable API.

From source (automatic)

To install the contents of the latest master branch, you can use

pipx install git+https://github.com/kcroker/dpsprep

or

uv tool install dpsprep --from git+https://github.com/kcroker/dpsprep

Extras must be specified after the URL, i.e.

pipx install git+https://github.com/kcroker/dpsprep[compress]

Sometimes a particular feature branch need to be tested. For installing a fixed revision (i.e. common/branch/tag), the following should work:

pipx install git+https://github.com/kcroker/dpsprep@rev[extra-name]

From source (manual)

Setting up the project up can be done via uv. Once inside the cloned repository, the environment for the program can be set up by simply running uv sync. After than, the following should work:

uv run dpsprep [OPTIONS] SRC [DEST]

You can also build and install the project, for example via pipx:

uv build --wheel
pipx install --include-deps dist/*.whl

[!INFO] Building package wheels is done via a custom in-tree backend that wraps uv-build and additionally creates a man page by introspecting the CLI.

If you want dpsprep to be able to use ocrmypdf from pipx's isolated environment, you must inject it explicitly via

pipx inject dpsprep ocrmypdf

Project setup

The project uses uv for managing Python versions, dependencies and building. Running uv sync will create a virtual environment with an appropriate Python version (based on .python-version) and install all development dependencies.

Other tasks like linting, type checking and building the documentation are described in poe_tasks.toml (configuration for poethepoet).

Run tox (via e.g. uv run tox or poe run test-multienv) to test the project in all supported environments.

If you plan to submit any work, consider also updating CHANGELOG.md.

Kevin's notes regarding the first version

I wrote this with the specific intent of converting ebooks in the DJVU format into PDFs for use with the fantastic (but pricey) Sony Digital Paper System.

DjVu technology is strikingly superior for many ebook applications, yet the Sony Digital Paper System (rev 1.3 US) only supports PDF technology: this is because its primary design purpose is not as an ereader. The device, however, is quite nearly the perfect ereader.

Unfortunately, all presently available DjVu to PDF tools seem to just dump flattened enormous TIFF images. This is ridiculous. Since PDF really can't do that much better on the way it stores image data, a 5-6x bloat cannot be avoided. However, none of the existing tools preserve:

  • The OCR'd text content
  • Table of Contents or Internal links

This is kind of silly, but until Sony's Digital Paper, there was no need to move functional DjVu files to PDFs. In order to make workable PDFs from DjVu files for use on the Digital Paper System, I have implemented in one location the following procedures detailed here:

By automating the procedure of user zetah for extracting the text and getting it in the correct locations: http://askubuntu.com/questions/46233/converting-djvu-to-pdf (OCR text transfer)

By implementing the procedure of user pyrocrasty for extracting the outline, and putting it into the PDF generated above: http://superuser.com/questions/801893/converting-djvu-to-pdf-and-preserving-table-of-contents-how-is-it-possible (bookmark transfer)

Metadata

Release files for dpsprep 2.8.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dpsprep 2.8.3
File Size Uploaded Provenance Actions
dpsprep-2.8.3.tar.gz 292.0 kB Without provenance Details for dpsprep-2.8.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for dpsprep 2.8.3
File Interpreter ABI Platform Actions
dpsprep-2.8.3-py3-none-any.whl Python 3 none any Details for dpsprep-2.8.3-py3-none-any.whl

Total release size: 348.5 kB

Release files / dpsprep-2.8.3.tar.gz

Download URL dpsprep-2.8.3.tar.gz
Size 292.0 kB
Tags Source
SHA-256 checksum
How to use checksums
171af7ecae10c60eb8e62c1c94f049f5a657c75b08c8c37b9b315b34f07d55c8
BLAKE2b-256 checksum
How to use checksums
f7defc192319a3b6a31de51413f1ae215974d3fc5bafc10adeea144443196748
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / dpsprep-2.8.3-py3-none-any.whl

Download URL dpsprep-2.8.3-py3-none-any.whl
Size 56.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9476c93037c2ecf8e403a73b95e0fcd41cea70567129f5160f6ac275a9f28f3a
BLAKE2b-256 checksum
How to use checksums
01088f0ebce63780e90432ed4fcccf14ce92b3bec69f537006807f66434b5456
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for dpsprep 2.8.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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