Skip to main content

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

https://mupdf.com/r/C-and-Python-APIs

Release files for mupdf 1.21.1.20230112.1504

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mupdf 1.21.1.20230112.1504
File Size Uploaded
mupdf-1.21.1.20230112.1504.tar.gz 83.1 MB Details

Built distributions (wheels)

Table of built distributions (wheels) for mupdf 1.21.1.20230112.1504
File
mupdf-1.21.1.20230112.1504-cp311-none-win_amd64.whl CPython 3.11 none Windows x86-64 Details
mupdf-1.21.1.20230112.1504-cp311-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.11 none Linux glibc 2.17+ x86-64 Details
mupdf-1.21.1.20230112.1504-cp310-none-win_amd64.whl CPython 3.10 none Windows x86-64 Details
mupdf-1.21.1.20230112.1504-cp310-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 none Linux glibc 2.17+ x86-64 Details
mupdf-1.21.1.20230112.1504-cp39-none-win_amd64.whl CPython 3.9 none Windows x86-64 Details
mupdf-1.21.1.20230112.1504-cp39-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.9 none Linux glibc 2.17+ x86-64 Details
mupdf-1.21.1.20230112.1504-cp38-none-win_amd64.whl CPython 3.8 none Windows x86-64 Details
mupdf-1.21.1.20230112.1504-cp38-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.8 none Linux glibc 2.17+ x86-64 Details
mupdf-1.21.1.20230112.1504-cp37-none-win_amd64.whl CPython 3.7 none Windows x86-64 Details
mupdf-1.21.1.20230112.1504-cp37-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.7 none Linux glibc 2.17+ x86-64 Details

Total release size: 430.9 MB

Release files / mupdf-1.21.1.20230112.1504.tar.gz

Download URL mupdf-1.21.1.20230112.1504.tar.gz
Size 83.1 MB
Tags Source
SHA-256 checksum
How to use checksums
aa581b73df3f23c37ce8965155f549f3f87ae264c00ead68406579157612cca6
BLAKE2b-256 checksum
How to use checksums
59bcefcdf44d3dd6a45f9f731e825fb17788d67ee4795694dc3bf8be9483b3e6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.15

Release files / mupdf-1.21.1.20230112.1504-cp311-none-win_amd64.whl

Download URL mupdf-1.21.1.20230112.1504-cp311-none-win_amd64.whl
Size 31.1 MB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
6c8b8905b9ba49b0ae7f404b63033208b01105b78272652f0f8f218c6d851c26
BLAKE2b-256 checksum
How to use checksums
7867614751892fc646753ec41ca0e630fbba15a91332989bdce9fde16bb18762
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.15

Release files / mupdf-1.21.1.20230112.1504-cp311-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL mupdf-1.21.1.20230112.1504-cp311-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 38.4 MB
Tags CPython 3.11 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
6ae0af788b6ac0c48585e468cdf7589f197c5e5e0cea5b7b37b5800d77141f12
BLAKE2b-256 checksum
How to use checksums
0fb1e3a5d8dd6c1cbc342e509b7a0bd0e43a3694c38877f5f32e4c2c3785d1e4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.15

Release files / mupdf-1.21.1.20230112.1504-cp310-none-win_amd64.whl

Download URL mupdf-1.21.1.20230112.1504-cp310-none-win_amd64.whl
Size 31.1 MB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
25cad3fc47bf8f1fe8fff9397209364a1d8fbea04d4afa108e6d3dc9ab05bb00
BLAKE2b-256 checksum
How to use checksums
9e27e581c79981f6ee12b3fc456c483f99805791535a7b972b0fba1798a379bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.15

Release files / mupdf-1.21.1.20230112.1504-cp310-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL mupdf-1.21.1.20230112.1504-cp310-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 38.4 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
90ba9e7e0aa90a4016deb5f16a8998e101bf3e94d575404334d51e6b80758660
BLAKE2b-256 checksum
How to use checksums
53eb388f3930311b27904665e6cc9d4c542827246d4ffa04fb38ecd04a6c181c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.15

Release files / mupdf-1.21.1.20230112.1504-cp39-none-win_amd64.whl

Download URL mupdf-1.21.1.20230112.1504-cp39-none-win_amd64.whl
Size 31.1 MB
Tags CPython 3.9 Windows x86-64
SHA-256 checksum
How to use checksums
a5cc322aefe6f46cfe912843d8d1dd46aa8ea84286c1672a80040ef587fabf3b
BLAKE2b-256 checksum
How to use checksums
cfb363b785a555eab74a8dfd93f581b99039e210d289a7665a696bfc18852454
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.15

Release files / mupdf-1.21.1.20230112.1504-cp39-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL mupdf-1.21.1.20230112.1504-cp39-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 38.4 MB
Tags CPython 3.9 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
f983db05f739be36063e1e32ed3934f6d485bfd8726fbac52d0f29b821461c8f
BLAKE2b-256 checksum
How to use checksums
fbc77c8dd4765c969a4aabb63422fede2b36b8c303dbc4a457d97f8a04c923cd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.15

Release files / mupdf-1.21.1.20230112.1504-cp38-none-win_amd64.whl

Download URL mupdf-1.21.1.20230112.1504-cp38-none-win_amd64.whl
Size 31.1 MB
Tags CPython 3.8 Windows x86-64
SHA-256 checksum
How to use checksums
2dfd9c4295e0c0785c1cf90e9349f3b6c4739a8c7dd80a5479fb2247667ab3f0
BLAKE2b-256 checksum
How to use checksums
5ede3d51dce7d4107a6bb6f7ee7abe9b9be5a10cef1dea66625eac4b8d27913b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.15

Release files / mupdf-1.21.1.20230112.1504-cp38-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL mupdf-1.21.1.20230112.1504-cp38-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 38.4 MB
Tags CPython 3.8 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
22dd7bc51adb64e883f986f2d8246bb75533dac56705781641499029bc2706a1
BLAKE2b-256 checksum
How to use checksums
d0d2cdd3b2001faf4be8806a96d4ce0624e6071f1cf15208fdb561d3871e8db9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.15

Release files / mupdf-1.21.1.20230112.1504-cp37-none-win_amd64.whl

Download URL mupdf-1.21.1.20230112.1504-cp37-none-win_amd64.whl
Size 31.1 MB
Tags CPython 3.7 Windows x86-64
SHA-256 checksum
How to use checksums
440a5319b2bbae8318ecfe6a7cf93b5e16a5076faceb1c7a84b7ac294336cff0
BLAKE2b-256 checksum
How to use checksums
107d755a4949d81a40ae4e0c94b95e551075177ccaedba129c190aa96f33d48d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.15

Release files / mupdf-1.21.1.20230112.1504-cp37-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL mupdf-1.21.1.20230112.1504-cp37-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 38.4 MB
Tags CPython 3.7 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
68b39c4434a76cf3791ff1546dc30c6b9b64f6a5757e20d1aba35d200fcb1363
BLAKE2b-256 checksum
How to use checksums
e73232716847f33c0c59745110469721b5c1df7bbcc5e61b9614d60e87ae7ba0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.15
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page