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
Hashes for mupdf-1.19.0.20220326.1214.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce11c9fc8d3cbf24a1c2b931ea92b7e2ac761f1664caeee4280d2194d3002949 |
|
MD5 | ff93037430753018aaf82943bbda53f8 |
|
BLAKE2b-256 | 9935c8d45673d7bb16b8273331a7d176fe2917a12724ed62355a6ddd07b3ccdb |
Hashes for mupdf-1.19.0.20220326.1214-cp39-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b101a3eb0594a899aa8ce7096c5c677746a774d3d4cbc46c492ffb92d2056c9e |
|
MD5 | e2d556d51c3260d72eb26efe1f056fe2 |
|
BLAKE2b-256 | b7822b2b63523f6d2e0a3a7628bc3a5ed5a1acd14c5768f99c614f4ea07fecf3 |
Hashes for mupdf-1.19.0.20220326.1214-cp39-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f166b3b0dd6a75192f9f9f2891d199e0f47044eaa1a40d610c742df7b18a3fed |
|
MD5 | 0929f0213a2892ac936d69fd244ef816 |
|
BLAKE2b-256 | 31b5df9df2b34dece0a2aa6c6ffae7c0e499277dc97463260583172842d81cd1 |
Hashes for mupdf-1.19.0.20220326.1214-cp39-none-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe96e839fca57616a74a95146a358e5121043c3176b20173a202073e17e033e7 |
|
MD5 | 2c94d8c53010accbe0b487ffdd9ca3b4 |
|
BLAKE2b-256 | 3ad211f36ec9f2d4b4314da72bb28747008cd75165a60967ccdbcd8bc797a631 |
Hashes for mupdf-1.19.0.20220326.1214-cp38-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 714bb5823c900c7464b92bb26e9029a4184344b9ea2d6296342d537026525659 |
|
MD5 | 61fe01e1493c7451d0627af0a8b3fce6 |
|
BLAKE2b-256 | 417cb3dc4f35d8feca948b36c624ac8cb323b093e60e833822a0cfb5b32e9a6d |
Hashes for mupdf-1.19.0.20220326.1214-cp38-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff969e644a2ef7d51c18ec8cdcd20aff9a41bcf893d92f195bd0fc25bd188346 |
|
MD5 | d53693921e0333bd54ca1c3f93b548b6 |
|
BLAKE2b-256 | 9ed50b8def99a5a94c2147603bd0f7d56b886aa0779bdb2091298602a79157bd |
Hashes for mupdf-1.19.0.20220326.1214-cp38-none-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 51842c3c646db3fd42fab269cab7aa27cbbd1735981f0bf3dc295b3c5725b1d7 |
|
MD5 | dc5bdfc101af6021371e0c61be6fe3a5 |
|
BLAKE2b-256 | d68325acc149dfceb78f09161183b85ac9da1d2bef0d01562527973a734fe5ee |
Hashes for mupdf-1.19.0.20220326.1214-cp37-none-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb5662178ecbdcfa2a84a22e00c02e0e8f88d2138ad464af43e0dd455e6a26e8 |
|
MD5 | 2b97a13cc6538a7e4827b1da37c56aba |
|
BLAKE2b-256 | 13953aaa8fe63b07f29db80a28e930dfe496974f3ebc3186feca2091be8a76bc |