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.20210929.1226.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ad7ebbe342e1af8005407725426326de4d58db811603c28e4f0928079118ef7 |
|
MD5 | 8a282c2e726f726a1664e2a28e43fdf6 |
|
BLAKE2b-256 | 32a8731c8a5f82f30bdbea09057ddea8048845b285e91769410ca26271fe3134 |
Hashes for mupdf-1.19.0.20210929.1226-cp39-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa4a67abbf5508c9c93565b01ff95d8e13069fa4263f31474f8ed3a0841e3293 |
|
MD5 | ff70b4b6a7a3dd77a6854e988ab0c034 |
|
BLAKE2b-256 | ecaf35e7dff519365f317838f3f7d1ede3738b7a87acbcc9204387cae9a10690 |
Hashes for mupdf-1.19.0.20210929.1226-cp39-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 88571597d68b5bcf9819426f4582d018c46b0c1a58d5b07d979597200edf6bfc |
|
MD5 | 6e2387826aec51b5810ca42bc1056221 |
|
BLAKE2b-256 | e9b754ee4002a500537a828e7a3441820c4f68e89f5bea8329d6b252cf51bb88 |
Hashes for mupdf-1.19.0.20210929.1226-cp39-none-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8bbdca7b893bab1e4bffd64842e3a88c94988963c4cefda194390175292ff0ba |
|
MD5 | 0b49cf732165f031369ccd9162dd1894 |
|
BLAKE2b-256 | d7658543e8b36a26ee387df531f6f140e8faea2f013ae125f2d511f971717a53 |
Hashes for mupdf-1.19.0.20210929.1226-cp38-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f94ec21bb691d7ee17dc2581e53a94d694c5dfe0d4a1be9e1c1bbb130bfcd5cf |
|
MD5 | bab124b53e45322bd0b111d339b83d54 |
|
BLAKE2b-256 | 808f07d760e5a1e74cc362c57469f4fa227d69afe1ebe12d08f2f2b5d98c2456 |
Hashes for mupdf-1.19.0.20210929.1226-cp38-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2a442593ce698593a2d2cb85b845a13645f3dbbaa17a8483475db058b3238f9d |
|
MD5 | 0d97d674a6709f7d04683edb78a28cde |
|
BLAKE2b-256 | f7a3ce1f589195adeaa7c59e413f88ae93b6d52224f42f0b3ff846e9f6c44731 |
Hashes for mupdf-1.19.0.20210929.1226-cp38-none-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a75bf8a8b6a90e796ab9eb6127fd9c916f1175dc7bf92041b50dbcc3a4e71562 |
|
MD5 | 0e2f464c0fe1c2e8f5b669409266289c |
|
BLAKE2b-256 | 8722c02affa1ab98f4eb646b76e50688256cca034ba788da4a1569caeaa29a38 |
Hashes for mupdf-1.19.0.20210929.1226-cp37-none-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0267959906bdd58af93739bb2b4972d4f4cb10a08390705f8f8391bdfb59893 |
|
MD5 | c423f17d060a6e2f381c56488058800b |
|
BLAKE2b-256 | 08173c7ce2d945a0115c5449b037a903039b2c2e2c4a37a652d82694b184d59e |