Auto-generated C++ and Python APIs for mupdf.


As of 2020-5-4:


  • C++ API is generated by mupdf:scripts/, which uses python-clang.
  • We require clang-6 or clang-7.
  • We generate C++ class wrappers for all fz structs.
  • We auto-detect fz_*() fns suitable for wrapping as constructors, methods or static methods.
  • Some generated classes have auto-generated support for iteration.
  • We add various custom methods/constructors.
  • We provide access via wrapper classes to 690 fz_*() fns.
  • There are a total of 890 fz_*() functions. Most of the omitted functions don't take struct args, e.g. fz_strlcpy(). Of the remaining, some use fz_* enums (which we don't yet wrap); see for more information.


  • Python API is generated by running SWIG on the C++ API's header files.
  • Python API is enough to allow implementation of mutool in Python - see mupdf:scripts/ and mupdf:scripts/
  • We work with swig-3 or swig-4.


  • We work on nuc1 and peeved and jules-laptop.
  • We require:
    • python-clang (version 6 or 7)
    • python3-dev (version 3.6 or later)
    • swig (version 3 or 4)


  • We use clang to extract doxygen-style comments, and propogate them into generated header files.
  • If swig is version 4+, we tell it to propogate comments into generated

Here are Doxygen html representations of the mupdf C API and the generated mupdf C++ API:

And pydoc html representation of the generated API:

mudpdf:scripts/mutool*.py are a Python re-implementation of the mutool application.

They do not use threads, or the include/mupdf/pdf/ functionality.


Auto-generated C++ headers and implementation files, plus test outputs (.html files have syntax-colouring):

Information about fz_*() fns that are not in the class-based API:

These were generated by the programme, which also runs g++ and SWIG to generate a Python module that gives a Python API:

The generated Python module is tested by the (rather hacky) test_mupdfcpp_swig() function in For convenience, this function and its output can be viewed in

Integration with mupdf git.

       [generated file]
       [generated file, implements C++ API]
       [generated file, implements Python API]
       [generated file, implements Python API internals]
       [implements C++ API]
       [implements Python API]
       [implements Python API internals]
                    *.cpp [generated files]
                        *.h [generated files]
                mupdfcpp_swig.cpp [generated by SWIG]
                mupdf_swig.i [generated by mupdfwraw.pynput to SWIG]


To build:

    cd mupdf/
    ./scripts/ -b all -t

-- Julian Smith - 2020-03-04


This topic: Main > UserList > JulianSmith > MupdfCppWrappers
Topic revision: r17 - 2020-05-05 - JulianSmith
This site is powered by the TWiki collaboration platform Powered by PerlCopyright 2014 Artifex Software Inc