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_*()).
Support for MuPDF function pointers with SWIG Director classes, allowing MuPDF to call Python callbacks.
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
File details
Details for the file mupdf-1.21.1.20230112.1504.tar.gz
.
File metadata
- Download URL: mupdf-1.21.1.20230112.1504.tar.gz
- Upload date:
- Size: 83.1 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
aa581b73df3f23c37ce8965155f549f3f87ae264c00ead68406579157612cca6
|
|
MD5 |
6352f8198b767b300126bfa1f2c18a93
|
|
BLAKE2b-256 |
59bcefcdf44d3dd6a45f9f731e825fb17788d67ee4795694dc3bf8be9483b3e6
|
File details
Details for the file mupdf-1.21.1.20230112.1504-cp311-none-win_amd64.whl
.
File metadata
- Download URL: mupdf-1.21.1.20230112.1504-cp311-none-win_amd64.whl
- Upload date:
- Size: 31.1 MB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
6c8b8905b9ba49b0ae7f404b63033208b01105b78272652f0f8f218c6d851c26
|
|
MD5 |
b574ea5e61ce335483dc31514e43f83c
|
|
BLAKE2b-256 |
7867614751892fc646753ec41ca0e630fbba15a91332989bdce9fde16bb18762
|
File details
Details for the file mupdf-1.21.1.20230112.1504-cp311-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: mupdf-1.21.1.20230112.1504-cp311-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 38.4 MB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
6ae0af788b6ac0c48585e468cdf7589f197c5e5e0cea5b7b37b5800d77141f12
|
|
MD5 |
11a5ddfc5fdbd63c5462ae92bbc441d4
|
|
BLAKE2b-256 |
0fb1e3a5d8dd6c1cbc342e509b7a0bd0e43a3694c38877f5f32e4c2c3785d1e4
|
File details
Details for the file mupdf-1.21.1.20230112.1504-cp310-none-win_amd64.whl
.
File metadata
- Download URL: mupdf-1.21.1.20230112.1504-cp310-none-win_amd64.whl
- Upload date:
- Size: 31.1 MB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
25cad3fc47bf8f1fe8fff9397209364a1d8fbea04d4afa108e6d3dc9ab05bb00
|
|
MD5 |
aff551408dd2f3d9d848d08ae8b7161e
|
|
BLAKE2b-256 |
9e27e581c79981f6ee12b3fc456c483f99805791535a7b972b0fba1798a379bc
|
File details
Details for the file mupdf-1.21.1.20230112.1504-cp310-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: mupdf-1.21.1.20230112.1504-cp310-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 38.4 MB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
90ba9e7e0aa90a4016deb5f16a8998e101bf3e94d575404334d51e6b80758660
|
|
MD5 |
ac90f8c421f79834b05b729bd86e52ae
|
|
BLAKE2b-256 |
53eb388f3930311b27904665e6cc9d4c542827246d4ffa04fb38ecd04a6c181c
|
File details
Details for the file mupdf-1.21.1.20230112.1504-cp39-none-win_amd64.whl
.
File metadata
- Download URL: mupdf-1.21.1.20230112.1504-cp39-none-win_amd64.whl
- Upload date:
- Size: 31.1 MB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
a5cc322aefe6f46cfe912843d8d1dd46aa8ea84286c1672a80040ef587fabf3b
|
|
MD5 |
4fb3607913d3b874e8f92c4c27c4ba7d
|
|
BLAKE2b-256 |
cfb363b785a555eab74a8dfd93f581b99039e210d289a7665a696bfc18852454
|
File details
Details for the file mupdf-1.21.1.20230112.1504-cp39-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: mupdf-1.21.1.20230112.1504-cp39-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 38.4 MB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
f983db05f739be36063e1e32ed3934f6d485bfd8726fbac52d0f29b821461c8f
|
|
MD5 |
193ed9e29213e733a348e09e115dd046
|
|
BLAKE2b-256 |
fbc77c8dd4765c969a4aabb63422fede2b36b8c303dbc4a457d97f8a04c923cd
|
File details
Details for the file mupdf-1.21.1.20230112.1504-cp38-none-win_amd64.whl
.
File metadata
- Download URL: mupdf-1.21.1.20230112.1504-cp38-none-win_amd64.whl
- Upload date:
- Size: 31.1 MB
- Tags: CPython 3.8, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
2dfd9c4295e0c0785c1cf90e9349f3b6c4739a8c7dd80a5479fb2247667ab3f0
|
|
MD5 |
5af6afbdc004b4c605d5cf77a9934c43
|
|
BLAKE2b-256 |
5ede3d51dce7d4107a6bb6f7ee7abe9b9be5a10cef1dea66625eac4b8d27913b
|
File details
Details for the file mupdf-1.21.1.20230112.1504-cp38-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: mupdf-1.21.1.20230112.1504-cp38-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 38.4 MB
- Tags: CPython 3.8, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
22dd7bc51adb64e883f986f2d8246bb75533dac56705781641499029bc2706a1
|
|
MD5 |
6da4e3f6478b4d99f189e2f0fc0c1706
|
|
BLAKE2b-256 |
d0d2cdd3b2001faf4be8806a96d4ce0624e6071f1cf15208fdb561d3871e8db9
|
File details
Details for the file mupdf-1.21.1.20230112.1504-cp37-none-win_amd64.whl
.
File metadata
- Download URL: mupdf-1.21.1.20230112.1504-cp37-none-win_amd64.whl
- Upload date:
- Size: 31.1 MB
- Tags: CPython 3.7, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
440a5319b2bbae8318ecfe6a7cf93b5e16a5076faceb1c7a84b7ac294336cff0
|
|
MD5 |
ba82f531c663a5ff0db907e9d8a3feff
|
|
BLAKE2b-256 |
107d755a4949d81a40ae4e0c94b95e551075177ccaedba129c190aa96f33d48d
|
File details
Details for the file mupdf-1.21.1.20230112.1504-cp37-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: mupdf-1.21.1.20230112.1504-cp37-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 38.4 MB
- Tags: CPython 3.7, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
68b39c4434a76cf3791ff1546dc30c6b9b64f6a5757e20d1aba35d200fcb1363
|
|
MD5 |
7f112e7f95ba2effcbb9bc7c0f3439c8
|
|
BLAKE2b-256 |
e73232716847f33c0c59745110469721b5c1df7bbcc5e61b9614d60e87ae7ba0
|