Skip to main content

Python bindings for the PDF toolkit and renderer MuPDF

Project description

PyMuPDF 1.20.0

logo

Release date: June 16, 2022

On PyPI since August 2016: Downloads

Author

Artifex, based on code by Jorj X. McKie and Ruikai Liu.

Introduction

PyMuPDF adds Python bindings and abstractions to MuPDF, a lightweight PDF, XPS, and eBook viewer, renderer, and toolkit. Both PyMuPDF and MuPDF are maintained and developed by Artifex Software, Inc.

MuPDF can access files in PDF, XPS, OpenXPS, CBZ, EPUB and FB2 (eBooks) formats, and it is known for its top performance and exceptional rendering quality.

With PyMuPDF you can access files with extensions like .pdf, .xps, .oxps, .cbz, .fb2 or .epub. In addition, about 10 popular image formats can also be handled like documents: .png, .jpg, .bmp, .tiff, etc.

Usage

For all supported document types (i.e. including images) you can

  • Decrypt the document.
  • Access meta information, links and bookmarks.
  • Render pages in raster formats (PNG and some others), or the vector format SVG.
  • Search for text.
  • Extract text and images.
  • Convert to other formats: PDF, (X)HTML, XML, JSON, text.
  • Do OCR (Optical Character Recognition) if Tesseract is installed.

To some degree, PyMuPDF can also be used as an image converter: it can read a range of input formats and can produce Portable Network Graphics (PNG), Portable Anymaps (PNM, etc.), Portable Arbitrary Maps (PAM), Adobe PostScript and Adobe Photoshop documents, making the use of other graphics packages obselete in these cases. But interfacing with e.g. PIL/Pillow for image input and output is easy as well.

For PDF documents, there exists a plethora of additional features: they can be created, joined or split up. Pages can be inserted, deleted, re-arranged or modified in many ways (including annotations and form fields).

  • Images and fonts can be extracted or inserted.

    You may want to have a look at this cool GUI example script, which lets you insert, delete, replace or re-position images under your visual control.

    If fontTools is installed, subsets can be built for eligible fonts based on their usage in the document. Especially for new PDFs, this can lead to significant file size reductions.

  • Embedded files are fully supported.

  • PDFs can be reformatted to support double-sided printing, posterizing, applying logos or watermarks

  • Password protection is fully supported: decryption, encryption, encryption method selection, permission level and user / owner password setting.

  • Support of the PDF Optional Content concept for images, text and drawings.

  • Low-level PDF structures can be accessed and modified.

  • Command line module "python -m fitz ...". A versatile utility with the following features

    • encryption / decryption / optimization
    • creation of sub-documents
    • document joining
    • image / font extraction
    • full support of embedded files
    • layout-preserving text extraction (all documents)

Have a look at the basic demos, the examples (which contain complete, working programs), and notebooks.

Documentation

Documentation is written using Sphinx and is available in various formats from the following sources. It currently is a combination of reference guide and user manual. For a quick start look at the tutorial and the recipes chapters.

The latest changelog can be viewed here.

Installation

PyMuPDF requires Python 3.7 or later.

For versions 3.7 and up, Python wheels exist for Windows (32bit and 64bit), Linux (64bit, Intel and ARM) and Mac OSX (64bit, Intel only), so it can be installed from PyPI in the usual way. To ensure pip support for the latest wheel platform tags, we strongly recommend to always upgrade pip first.

python -m pip install --upgrade pip
python -m pip install --upgrade pymupdf

There are no mandatory external dependencies. However, some optional features become available only if additional packages are installed:

  • Pillow for using pillow image output directly from PyMuPDF
  • fontTools for creating font subsets.
  • pymupdf-fonts contains some nice fonts for your text output.
  • Tesseract-OCR for optical character recognition in images and document pages. Tesseract is separate software, not a Python package. To enable OCR functions in PyMuPDF, the system environment variable "TESSDATA_PREFIX" must be defined and contain the tessdata folder name of the Tesseract installation location.

Older wheels - also with support for older Python versions - can be found here and on PyPI.

Note: If pip cannot find a wheel that is compatible with your platform, it will automatically build and install from source using the PyMuPDF sdist; this requires only that SWIG is installed on your system.

[New in PyMuPDF-1.20: there is no need to separately build or install MuPDF; the required MuPDF source code is already in the sdist and is automatically built into PyMuPDF.]

License and Copyright

PyMuPDF and MuPDF are available under both, open-source AGPL and commercial license agreements.

Please read the full text of the AGPL license agreement (which is also included here in file COPYING) to ensure that your use case complies with the guidelines of this license. If you determine you cannot meet the requirements of the AGPL, please contact Artifex for more information regarding a commercial license.

Artifex is the exclusive commercial licensing agent for MuPDF.

Artifex, the Artifex logo, MuPDF, and the MuPDF logo are registered trademarks of Artifex Software Inc. PyMuPDF and the PyMuPDF logo are trademarks of Artifex Software, Inc. © 2022 Artifex Software, Inc. All rights reserved.

Contact

Please use the Discussions menu for questions, comments, or asking for help, and submit issues here.

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

PyMuPDF-1.20.0.tar.gz (90.4 MB view hashes)

Uploaded Source

Built Distributions

PyMuPDF-1.20.0-cp310-cp310-win_amd64.whl (6.6 MB view hashes)

Uploaded CPython 3.10 Windows x86-64

PyMuPDF-1.20.0-cp310-cp310-win32.whl (5.9 MB view hashes)

Uploaded CPython 3.10 Windows x86

PyMuPDF-1.20.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.9 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

PyMuPDF-1.20.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (8.8 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

PyMuPDF-1.20.0-cp310-cp310-macosx_10_9_x86_64.whl (7.7 MB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

PyMuPDF-1.20.0-cp39-cp39-win_amd64.whl (6.6 MB view hashes)

Uploaded CPython 3.9 Windows x86-64

PyMuPDF-1.20.0-cp39-cp39-win32.whl (5.9 MB view hashes)

Uploaded CPython 3.9 Windows x86

PyMuPDF-1.20.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.9 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

PyMuPDF-1.20.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (8.8 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

PyMuPDF-1.20.0-cp39-cp39-macosx_10_9_x86_64.whl (7.7 MB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

PyMuPDF-1.20.0-cp38-cp38-win_amd64.whl (6.6 MB view hashes)

Uploaded CPython 3.8 Windows x86-64

PyMuPDF-1.20.0-cp38-cp38-win32.whl (5.9 MB view hashes)

Uploaded CPython 3.8 Windows x86

PyMuPDF-1.20.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.8 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

PyMuPDF-1.20.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (8.7 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64

PyMuPDF-1.20.0-cp38-cp38-macosx_10_9_x86_64.whl (7.7 MB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

PyMuPDF-1.20.0-cp37-cp37m-win_amd64.whl (6.6 MB view hashes)

Uploaded CPython 3.7m Windows x86-64

PyMuPDF-1.20.0-cp37-cp37m-win32.whl (5.9 MB view hashes)

Uploaded CPython 3.7m Windows x86

PyMuPDF-1.20.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.8 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

PyMuPDF-1.20.0-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (8.7 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ ARM64

PyMuPDF-1.20.0-cp37-cp37m-macosx_10_9_x86_64.whl (7.7 MB view hashes)

Uploaded CPython 3.7m macOS 10.9+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page