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.20210521.1738.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 89bae8572258166e1f4e7f83b9e196c998077d49f094dec6816047748b794db3 |
|
MD5 | 99e01988d6f639a2b291f4f4e4c64604 |
|
BLAKE2b-256 | fd952258d4a5040adf5bf95b19d78de443ec8d8d612818b82f06aa6e659aa6cf |
Hashes for mupdf-1.18.0.20210521.1738-cp39-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e078dbf3784eee6cf2444c4c5388dc9b1f7fe9015dfae0662e9badd95ef97862 |
|
MD5 | 1fd7194fa86901a14b5b7c798d32cb95 |
|
BLAKE2b-256 | 59339f9ecf513d38d2110b394034133affa67e35b6dd2d827078c59ff52c16df |
Hashes for mupdf-1.18.0.20210521.1738-cp39-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5351265130f60654af73a0d4f0382b8b0152a890f88b32f214a449af2d51a37a |
|
MD5 | 6ea68f586f9d79ce622eaed2227ce121 |
|
BLAKE2b-256 | d7e48bf7093ae40a2e7d8d3056adcf5e11d8832f12d79a8a50bbbf5ebc937859 |
Hashes for mupdf-1.18.0.20210521.1738-cp39-none-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d8b63f85060186637993c6425240420b868e759bc41a0c20ed547db247cac4b |
|
MD5 | 027ba919e00010ef273294cffdbd43ce |
|
BLAKE2b-256 | 08d051ac4baad8abb7321174227de816da40406f0bb7546891128e22e4c4620e |
Hashes for mupdf-1.18.0.20210521.1738-cp38-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2af708b33289596626590add8b3e87b39501cb7a437e13c43cbf15634b766831 |
|
MD5 | 5fa1838afaa01b35a6ee59c3699b3ad3 |
|
BLAKE2b-256 | 3165a56dd293753cc3fdbaef3e1e44b3a3a2bde7d10dfe1974c74f52fa9b2bfa |
Hashes for mupdf-1.18.0.20210521.1738-cp38-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b378973dffde856570c52818bcabb3972de7850d7d1bdad5546eb99f70901023 |
|
MD5 | eb2f93c3151d4b5b387b29889b7a582f |
|
BLAKE2b-256 | 188037dfd46fe69bb13bd78a25b11ecc8f6faeb0d0aca54c3a8ae2b8f0cea408 |
Hashes for mupdf-1.18.0.20210521.1738-cp38-none-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ae374e8187dd6db65d9ae214df3ad17b1a1b88b085722da01b2eec2d38072645 |
|
MD5 | d7f7d41973feaf9f1eac45bc123c6448 |
|
BLAKE2b-256 | 207929b8cd0c3dc31a3b051f5df239460f021de7e1dc8736e860d6412a3994ff |
Hashes for mupdf-1.18.0.20210521.1738-cp37-none-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | feabf5dd160d513e043c29fae2ea4c6710d14ec2630ce60e381ba82b12a3fc89 |
|
MD5 | 9ab090ce7f1183f27b2756435a5672db |
|
BLAKE2b-256 | 5d93e904491151b14f6f3ddec3d8dcd1160a205fe5b35bb2f49fbc0a4e5bfaf3 |