File Loader
PyMuPDF Terminal
Extensive documentation, version controlled with Read the Docs
Get started quickly with the basics or dive into the full API.Open Source Software (and always will be)
Find us on Github, feel free to contribute!Discover the PyMuPDF online web console
Please run the samples and/or type your own Python code to learn PyMuPDF.
Print the version of PyMuPDF
pymupdf.version
Load a document from the web
import pyodide.httpr = await pyodide.http.pyfetch('https://pymupdf.io/docs/mupdf_explored.pdf')data = await r.bytes()doc = pymupdf.Document(stream=data)print(f'Is PDF: {doc.is_pdf}')print(f'Number of pages: {doc.page_count}')
Count the pages in a document
import pyodide.httpr = await pyodide.http.pyfetch('https://pymupdf.io/docs/mupdf_explored.pdf')data = await r.bytes()doc = pymupdf.Document(stream=data)for page in doc:print(f'Page: {page.number}')
Find the annotations in a document
import pyodide.httpr = await pyodide.http.pyfetch('https://pymupdf.io/docs/mupdf_explored.pdf')data = await r.bytes()doc = pymupdf.Document(stream=data)for page in doc:for annot in page.annots():print(f'Annotation on page: {page.number} with type: {annot.type} and rect: {annot.rect}')
Scrub a document and add a button to save the result
import pyodide.httpr = await pyodide.http.pyfetch('https://raw.githubusercontent.com/bpampuch/pdfmake/0.2.14/examples/pdfs/links.pdf')data = await r.bytes()doc = pymupdf.Document(stream=data)doc.scrub(reset_responses=False)import base64bytes = doc.tobytes(garbage=3, deflate=True)data_uri = 'data:application/octet-stream;base64,' + base64.b64encode(bytes).decode('ascii')import jssave_button = js.document.getElementById('fileSaveButton')if not save_button:open_button = js.document.getElementById('fileOpenButton')if open_button:save_button = js.document.createElement('button')save_button.setAttribute('id', 'fileSaveButton')save_button.style.display = 'inline-block'save_button.style.marginLeft = '1em'open_button.parentNode.appendChild(save_button)if save_button:save_button.innerHTML = '<a href="' + data_uri + '" download="result.pdf">Save</a>'save_anchor = save_button.childNodes[0]save_anchor.style.color = 'inherit'save_anchor.style.textDecoration = 'none'