Update documentation for DjVu output

This commit is contained in:
RunasSudo 2025-05-09 00:12:36 +10:00
parent edba14ff2c
commit bbc327ba5a
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
6 changed files with 16 additions and 15 deletions

View File

@ -1,6 +1,6 @@
# pdf-segmented
Generate PDFs (or DJVU) using separate compression for foreground and background
Generate PDFs (or DjVu) using separate compression for foreground and background
## Usage
@ -14,7 +14,7 @@ All black pixels (#000000) will be considered to be foreground, and all remainin
The foreground will be compressed losslessly using [JBIG2](https://en.wikipedia.org/wiki/JBIG2). The background will be compressed lossily using [JPEG](https://en.wikipedia.org/wiki/JPEG). JPEG quality can be controlled using the `--jpeg-quality` option; the default is the Pillow default (75% at time of writing).
Additional compression algorithms are supported (JPEG 2000, PNG); see `--help` for detailed options. DJVU output (foreground JB2, background IW44) is also supported.
Additional compression algorithms are supported (JPEG 2000, PNG); see `--help` for detailed options. DjVu output (foreground JB2, background IW44) is also supported.
## Dependencies
@ -22,5 +22,6 @@ Additional compression algorithms are supported (JPEG 2000, PNG); see `--help` f
* [NumPy](https://numpy.org/) (tested using 2.2.5)
* [Pillow](https://pillow.readthedocs.io/en/stable/) (tested using 11.2.1)
* [pikepdf](https://pikepdf.readthedocs.io/en/latest/) (tested using 9.7.0)
* [DjVuLibre](https://djvu.sourceforge.net/) (tested using 3.5.28) – for DjVu output
* [ImageMagick](https://imagemagick.org/) (tested using 7.1.1.47)
* [jbig2enc](https://github.com/agl/jbig2enc) (tested using 0.30)
* [jbig2enc](https://github.com/agl/jbig2enc) (tested using 0.30) – for JBIG2

View File

@ -81,10 +81,10 @@ def convert_file(
if output_format == 'djvu':
if bg_compression != 'iw44':
print('Error: Unsupported --bg-compression for DJVU format (supported: iw44)')
print('Error: Unsupported --bg-compression for DjVu format (supported: iw44)')
sys.exit(1)
if fg_compression != 'jb2':
print('Error: Unsupported --fg-compression for DJVU format (supported: jb2)')
print('Error: Unsupported --fg-compression for DjVu format (supported: jb2)')
sys.exit(1)
# Get input pages

View File

@ -33,8 +33,8 @@ class IW44Layer(CompressedLayer):
os.unlink(self.filename)
def iw44_compress_layer(layer: Image, dpi: float, tempdir: str) -> IW44Layer:
assert_has_c44('IW44 compression requires DjvuLibre')
assert_has_djvuextract('IW44 compression requires DjvuLibre')
assert_has_c44('IW44 compression requires DjVuLibre')
assert_has_djvuextract('IW44 compression requires DjVuLibre')
# Save image to PBM temporarily
_, ppm_file = tempfile.mkstemp(suffix='.ppm', dir=tempdir)

View File

@ -33,7 +33,7 @@ class JB2Layer(CompressedLayer):
os.unlink(self.filename)
def jb2_compress_layer(layer: Image, dpi: float, tempdir: str) -> JB2Layer:
assert_has_cjb2('JB2 compression requires DjvuLibre')
assert_has_cjb2('JB2 compression requires DjVuLibre')
# Save image to PPM temporarily
_, pbm_file = tempfile.mkstemp(suffix='.pbm', dir=tempdir)

View File

@ -30,8 +30,8 @@ def djvu_write_pages(
tempdir: str
) -> None:
assert_has_djvm('DJVU output requires DjvuLibre')
assert_has_djvumake('DJVU output requires DjvuLibre')
assert_has_djvm('DjVu output requires DjVuLibre')
assert_has_djvumake('DjVu output requires DjVuLibre')
djvu_page_files = []

View File

@ -17,27 +17,27 @@
import shutil
import sys
def assert_has_c44(error_message: str = 'DjvuLibre is required') -> None:
def assert_has_c44(error_message: str = 'DjVuLibre is required') -> None:
if shutil.which('c44') is None:
print('Error: {} (c44 not found on PATH)'.format(error_message), file=sys.stderr)
sys.exit(1)
def assert_has_cjb2(error_message: str = 'DjvuLibre is required') -> None:
def assert_has_cjb2(error_message: str = 'DjVuLibre is required') -> None:
if shutil.which('cjb2') is None:
print('Error: {} (cjb2 not found on PATH)'.format(error_message), file=sys.stderr)
sys.exit(1)
def assert_has_djvm(error_message: str = 'DjvuLibre is required') -> None:
def assert_has_djvm(error_message: str = 'DjVuLibre is required') -> None:
if shutil.which('djvm') is None:
print('Error: {} (djvm not found on PATH)'.format(error_message), file=sys.stderr)
sys.exit(1)
def assert_has_djvuextract(error_message: str = 'DjvuLibre is required') -> None:
def assert_has_djvuextract(error_message: str = 'DjVuLibre is required') -> None:
if shutil.which('djvuextract') is None:
print('Error: {} (djvuextract not found on PATH)'.format(error_message), file=sys.stderr)
sys.exit(1)
def assert_has_djvumake(error_message: str = 'DjvuLibre is required') -> None:
def assert_has_djvumake(error_message: str = 'DjVuLibre is required') -> None:
if shutil.which('djvumake') is None:
print('Error: {} (djvumake not found on PATH)'.format(error_message), file=sys.stderr)
sys.exit(1)