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.19.0.20220323.1255.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | f4ed1f3a2c6e50ce8121814cc202bc7f27a3bc4fd4c96cd9a709e91105dc3aa6 |
|
MD5 | 1172b7947ad6cef329d45b4f93f9d154 |
|
BLAKE2b-256 | 6334b9832ee6c31fed7ddb3ab0ab60fad39780ab6d38f405d61f45bc746808dd |
Hashes for mupdf-1.19.0.20220323.1255-cp39-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74092c3decc52ae25bf248e93ea469d993ff864a65a1d017af454dadaf18da75 |
|
MD5 | 297deb05b03d50c94c998dfd94c6433a |
|
BLAKE2b-256 | 5804df6444e9f8f504f66f47667793619d240b0463d76f221f68bc90202a9639 |
Hashes for mupdf-1.19.0.20220323.1255-cp39-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22a95392c4b1471ead079a704c9b606a9407d2c8bf1a6f05a1d9f22ec9debf3b |
|
MD5 | 274d6e354e85a880e8113a3dda498978 |
|
BLAKE2b-256 | ce951d9f92c63304332382e7cb5e2cdd37c6474badf80f7c397d0ef28e294299 |
Hashes for mupdf-1.19.0.20220323.1255-cp39-none-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aea188f854a5e121f504d0054b401d68aafae8c315815defd8eb34d08c96de75 |
|
MD5 | b6847b921df6b84eaf2d59868de0429e |
|
BLAKE2b-256 | 4539acc9136ecc9f6cdb1e223edfe04dba38d3dda3fc32652b7182d000e306aa |
Hashes for mupdf-1.19.0.20220323.1255-cp38-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 69add6d578d84f32eb5850295793dba98e8ad661e1e524345786a03b9d7f424b |
|
MD5 | e53e73acf694f178ef67d848918a3eef |
|
BLAKE2b-256 | b7cdab5c37177ec76dc92750e7a22fce5da2ee49e8aaa1588f3a71d672663b7e |
Hashes for mupdf-1.19.0.20220323.1255-cp38-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 00f25c4aa7f62b7483d98f675d30681b5f1bbcc68783fd9ad2351969c09b8216 |
|
MD5 | a51f3c875b1bfc4f6fed2b95ee883349 |
|
BLAKE2b-256 | 086966b82aedb6ce2de55ca244226c1a73eb3188990da0a6e2d819292b6078c2 |
Hashes for mupdf-1.19.0.20220323.1255-cp38-none-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ca4cd80d9e1824bb7c45003b7656cf289368f929d5c08e378401f872e3d5196 |
|
MD5 | 414ee6e600b5bb8408bae6fd4ff061dd |
|
BLAKE2b-256 | 8ec177a72307f401e6d50d7165490a492488f9cd4bc75886af1c813260b35148 |
Hashes for mupdf-1.19.0.20220323.1255-cp37-none-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 36cb76587b8d705194fba5b05193059a8907fa66fcab9bcb83842315f2f75041 |
|
MD5 | c8e768c41bebefbcf52c9eab6acbaaa4 |
|
BLAKE2b-256 | 344d38246507a3fafc1053673cd24a7dfd6502b3444cff25a5711049648ad46f |