A DjVu to PDF converter
Project description
dpsprep
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:
libtifffor bitonal image compression.libjpeg(orlibjpeg-turbo) for multitotal (RGB or grayscale) compression.OCRmyPDFandjbig2encfor 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.
[!TIP] A few people have reported installation problems; see this possible solution and this sample Dockerfile.
[!NOTE] Note that Windows support in
djvulibre-pythonrequires 64-bitdjvulibre, and they only officially distribute 32-bit Windows packages. If you manage to make it work, consider opening a pull request.
[!TIP] If you are packaging this for some other package manager, consider using PEP-517 tools as shown in this PKGBUILD file.
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]
[!NOTE] Previous versions used
pyenvfor managing Python versions andpoetryfor managing dependencies and building. Since then the project migrated touv, which subsumes both and provides other niceties.
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.
[!TIP] The build can fail if the
uv_buildPython package is not installed. Make sure not only theuvbinary, but also the corresponding Python package is available. For example, in the Arch repositories, these are distinct packages,uvandpython-uv. Alternatively, try to install theuv-buildPyPI package (python-uv-buildin Arch) explicitly in this case.
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
[!NOTE] Previous versions of the tool itself used to depend on third-party binaries, but this is no longer the case. The test fixtures are checked in, however regenerating them (see
./fixtures/Makefile) requirespdflatex(texlive, among others),gs(Ghostscript),oxipng(oxipng),pdftotext(Poppler),djvudigital(GSDjVU) anddjvused(DjVuLibre).
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)
Project details
Release history Release notifications | RSS feed
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 dpsprep-2.8.1.tar.gz.
File metadata
- Download URL: dpsprep-2.8.1.tar.gz
- Upload date:
- Size: 274.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e3a2842e6d05b1aa2b1b32f13c791a68d0ca6b439d88c2ee3fb061191985363f
|
|
| MD5 |
6923d893aefd79af5d625e14964dd77e
|
|
| BLAKE2b-256 |
5ee1f014729652d55e892d64f627225c53b9b0b0657cca9e7ddbd06d61f0cb97
|
File details
Details for the file dpsprep-2.8.1-py3-none-any.whl.
File metadata
- Download URL: dpsprep-2.8.1-py3-none-any.whl
- Upload date:
- Size: 41.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5fa722aadb11f2512323442c69ae845f011d947993fff13e0cdac4b0f2af2fb5
|
|
| MD5 |
728b4566ceeab4295381a12d47ea6d8f
|
|
| BLAKE2b-256 |
79f9e1441eb0ac39b13c5a857e9283cf921496fc18a80b9022431495515187f0
|