Python bindings for MuPDF library.
Project description
Summary
Python bindings for the MuPDF PDF library.
A python module called mupdf.
Generated from the MuPDF C++ API, which is itself generated from the MuPDF C API.
Provides Python functions that wrap most fz_ and pdf_ functions.
Provides Python classes that wrap most fz_ and pdf_ structs.
Class methods provide access to most of the underlying C API functions (except for functions that don’t take struct args such as fz_strlcpy()).
MuPDF’s setjmp/longjmp exceptions are converted to Python exceptions.
Functions and methods do not take fz_context arguments. (Automatically-generated per-thread contexts are used internally.)
Wrapper classes automatically handle reference counting of the underlying structs (with internal calls to fz_keep_*() and fz_drop_*()).
Provides a small number of extensions beyond the basic C API:
Some generated classes have extra support for iteration.
Some custom class methods and constructors.
Simple ‘POD’ structs have __str__() methods, for example mupdf.Rect is represented like: (x0=90.51 y0=160.65 x1=501.39 y1=215.6).
Example usage
Minimal Python code that uses the mupdf module:
import mupdf document = mupdf.Document('foo.pdf')
A simple example Python test script (run by scripts/mupdfwrap.py -t) is:
scripts/mupdfwrap_test.py
More detailed usage of the Python API can be found in:
scripts/mutool.py
scripts/mutool_draw.py
Here is some example code that shows all available information about document’s Stext blocks, lines and characters:
#!/usr/bin/env python3 import mupdf def show_stext(document): ''' Shows all available information about Stext blocks, lines and characters. ''' for p in range(document.count_pages()): page = document.load_page(p) stextpage = mupdf.StextPage(page, mupdf.StextOptions()) for block in stextpage: block_ = block.m_internal log(f'block: type={block_.type} bbox={block_.bbox}') for line in block: line_ = line.m_internal log(f' line: wmode={line_.wmode}' + f' dir={line_.dir}' + f' bbox={line_.bbox}' ) for char in line: char_ = char.m_internal log(f' char: {chr(char_.c)!r} c={char_.c:4} color={char_.color}' + f' origin={char_.origin}' + f' quad={char_.quad}' + f' size={char_.size:6.2f}' + f' font=(' + f'is_mono={char_.font.flags.is_mono}' + f' is_bold={char_.font.flags.is_bold}' + f' is_italic={char_.font.flags.is_italic}' + f' ft_substitute={char_.font.flags.ft_substitute}' + f' ft_stretch={char_.font.flags.ft_stretch}' + f' fake_bold={char_.font.flags.fake_bold}' + f' fake_italic={char_.font.flags.fake_italic}' + f' has_opentype={char_.font.flags.has_opentype}' + f' invalid_bbox={char_.font.flags.invalid_bbox}' + f' name={char_.font.name}' + f')' ) document = mupdf.Document('foo.pdf') show_stext(document)
More information
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 Distributions
Hashes for mupdf-1.18.0.20210805.1716.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | a7e45a967a1d89d2191cd1240c5abb6a2f5ca05c11df8a475a8c872aa561748b |
|
MD5 | 79cd202a6abc0eed09273420cb28c087 |
|
BLAKE2b-256 | 6079d02d51697d3762b053d69701426e4204169a54756f655df7013861c983bb |
Hashes for mupdf-1.18.0.20210805.1716-cp39-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f767012fd660afe8036a074f41d45e841131876a519a3d876f526594b8f4f23c |
|
MD5 | 02f8bc7c906a1b1177ef107c2462f1b3 |
|
BLAKE2b-256 | ed50c0412ba6424907d880d334afd715ea93380b19455447c79f56a1558e31f7 |
Hashes for mupdf-1.18.0.20210805.1716-cp39-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f2dc558f59db40df5e66ae7193951bc6cae38d19d6cd99e7f40736e4414b2cae |
|
MD5 | 79a1f86d5a83563f62288ee1a02580bf |
|
BLAKE2b-256 | bbc931682b0b8a36da28a80112a848aa0384e1e0cada65c434396b0c239ea6be |
Hashes for mupdf-1.18.0.20210805.1716-cp39-none-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | db8220374b84739aa798ef076cedde3c90b3810f4e67159ecb9c1cd0b646f93c |
|
MD5 | a0a421e7e18ebb206fc8e5aaf0e0cff4 |
|
BLAKE2b-256 | 7e3e15e4c842e29672a11cf538f2705d4f3ce409482c8822739bb85e8bb23dc9 |
Hashes for mupdf-1.18.0.20210805.1716-cp38-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 589a9c81164583c98b049e77dd1258bc2c1b0b69aaa6f89606cb49e6a0923a41 |
|
MD5 | 2c1f509887bc801e5ddac1e37ce52468 |
|
BLAKE2b-256 | 630acfa89b1f2bc3457fcd5f69930266c3709f217c10c982fb4fc1caaf23f310 |
Hashes for mupdf-1.18.0.20210805.1716-cp38-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e5c93868b254e7d1bb57e80074ba4fa2bec42f391c37a828321237ab5a226ee1 |
|
MD5 | 54e513a9fd6cbfd4941047bef2d4b43b |
|
BLAKE2b-256 | 6266db4f7c7334efe5fc18b8b40bb35c115601b6cf6949053fdedf94ffb9bd73 |
Hashes for mupdf-1.18.0.20210805.1716-cp38-none-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | abbd0211d2df490a634696d9e4d03a8623450a9d5ee93e061484bae6933c486f |
|
MD5 | 41d7d896f43f3e90e71ee5b15f113707 |
|
BLAKE2b-256 | c017c825c0e7715cc6cfb5d6aee878c3dbdc8fd514971697a3925399d77c76f1 |
Hashes for mupdf-1.18.0.20210805.1716-cp37-none-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0cdbf48d9b36446c21a5cfce7bbefa8a18346ce573fe339861b0f43c876df7e0 |
|
MD5 | e90abfaabb11492e1875003213aade11 |
|
BLAKE2b-256 | 8ae0168857c7cd17186f3050ff215e39e9dfa9d32d0d1ec68ade43d9043ce413 |