{"id":8501,"library":"PyMuPDF-pro","title":"PyMuPDF-pro","description":"PyMuPDF-pro is a commercial extension for the open-source PyMuPDF library. It enables robust handling of Office documents (e.g., .doc, .docx, .ppt, .pptx, .xls, .xlsx) and other formats not natively supported by PyMuPDF. It facilitates text and table extraction, document conversion to PDF, and more. The current version is 1.27.2.2, with releases typically aligning with PyMuPDF updates and feature enhancements.","status":"active","version":"1.27.2.2","language":"en","source_language":"en","source_url":"https://github.com/pymupdf/PyMuPDF-pro","tags":["PDF","Office Documents","document processing","conversion","docx","xlsx","pptx","commercial"],"install":[{"cmd":"pip install PyMuPDF-pro","lang":"bash","label":"Install PyMuPDF-pro"}],"dependencies":[{"reason":"PyMuPDF-pro extends the core PyMuPDF library (`fitz` module). PyMuPDF must be installed for PyMuPDF-pro's features to be available and functional.","package":"PyMuPDF","optional":false}],"imports":[{"note":"PyMuPDF-pro extends the 'fitz' module from the PyMuPDF library, making its additional functions (like open_office_document) available directly under the 'fitz' namespace after this import.","symbol":"fitz","correct":"import fitz"},{"note":"The 'set_license' function is added by PyMuPDF-pro to the 'fitz.utils' submodule (from PyMuPDF) for activating the commercial license.","symbol":"fitz.utils.set_license","correct":"import fitz"},{"note":"The 'open_office_document' function, which handles Office file types, is made available directly under the 'fitz' module by PyMuPDF-pro.","symbol":"fitz.open_office_document","correct":"import fitz"}],"quickstart":{"code":"import os\nimport fitz # PyMuPDF-pro extends PyMuPDF's 'fitz' module\nfrom pathlib import Path\n\n# --- IMPORTANT: License Key Setup ---\n# PyMuPDF-pro requires a commercial license key.\n# Obtain your key from Artifex Software and set it as an environment variable,\n# or replace 'YOUR_ACTUAL_LICENSE_KEY_HERE'.\nlicense_key = os.environ.get('PYMUPDFPRO_LICENSE', 'YOUR_ACTUAL_LICENSE_KEY_HERE')\n\nif license_key == 'YOUR_ACTUAL_LICENSE_KEY_HERE':\n    print(\"WARNING: Please set the 'PYMUPDFPRO_LICENSE' environment variable or replace the placeholder.\")\n    print(\"Without a valid license, PyMuPDF-pro features will not function correctly.\")\nelse:\n    try:\n        fitz.utils.set_license(license_key)\n        print(\"PyMuPDF-pro license key setup attempted.\")\n    except AttributeError:\n        print(\"ERROR: 'fitz.utils.set_license' not found. Is PyMuPDF-pro installed?\")\n        exit(1)\n    except Exception as e:\n        print(f\"ERROR: Failed to set PyMuPDF-pro license: {e}\")\n        exit(1)\n\n# --- Example: Convert a DOCX file to PDF ---\n# Replace 'path/to/your/document.docx' with an actual Office file path.\n# You can use any supported format like .doc, .docx, .ppt, .pptx, .xls, .xlsx.\ninput_file = Path(os.environ.get('PYMUPDFPRO_INPUT_FILE', 'path/to/your/document.docx'))\noutput_file = Path(\"output.pdf\")\n\nif not input_file.exists() or 'path/to/your/document.docx' in str(input_file):\n    print(f\"\\nWARNING: Input file '{input_file}' not found or is a placeholder.\")\n    print(\"Please provide a valid path to an Office document (e.g., .docx) for conversion.\")\n    # For a truly runnable example without manual setup, one might create a dummy.\n    # For this quickstart, we'll indicate failure if the file isn't provided.\n    exit(1)\n\ntry:\n    # Use fitz.open_office_document (functionality added by PyMuPDF-pro)\n    doc = fitz.open_office_document(str(input_file))\n    doc.save(str(output_file)) # Save as PDF (default format)\n    doc.close()\n    print(f\"\\nSuccessfully converted '{input_file.name}' to '{output_file.name}'.\")\n\nexcept fitz.EmptyFilename:\n    print(f\"ERROR: Input file path is invalid or empty: '{input_file}'.\")\n    exit(1)\nexcept Exception as e:\n    print(f\"An error occurred during conversion: {e}\")\n    # Common error here if license is invalid: 'RuntimeError: License key expired or not valid'\n    exit(1)\nfinally:\n    # Clean up the output file for a clean runnable example\n    if output_file.exists():\n        os.remove(output_file)\n        print(f\"Cleaned up output file: {output_file}\")","lang":"python","description":"This quickstart demonstrates how to use PyMuPDF-pro to convert an Office document (like DOCX) to PDF. It highlights the critical step of setting your commercial license key and then utilizes the `fitz.open_office_document` function provided by the extension. Remember to replace the placeholder path with an actual Office document."},"warnings":[{"fix":"Obtain a commercial license key from Artifex Software and ensure it is correctly passed to `fitz.utils.set_license()` at the start of your application.","message":"PyMuPDF-pro requires a valid commercial license key to unlock its functionality. Without a key set via `fitz.utils.set_license()`, most operations on Office documents will fail with a license error.","severity":"breaking","affected_versions":"All versions"},{"fix":"Ensure both `PyMuPDF` and `PyMuPDF-pro` are installed: `pip install PyMuPDF PyMuPDF-pro`.","message":"PyMuPDF-pro extends the `fitz` module of PyMuPDF. Therefore, PyMuPDF must be installed alongside PyMuPDF-pro for the extensions to be active and for functions like `fitz.open_office_document` to be available.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Upgrade your Python environment to version 3.9 or newer.","message":"PyMuPDF-pro supports Python versions 3.9 and higher. Using it with older Python versions will result in installation or runtime errors.","severity":"gotcha","affected_versions":"<3.9"},{"fix":"Monitor resource usage for large documents and consider processing documents in batches or on systems with ample resources. Optimize document structures if possible.","message":"Processing large or complex Office documents (especially conversion or detailed extraction) can be resource-intensive, requiring significant CPU and memory. Performance may vary based on document complexity and system resources.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Ensure both PyMuPDF and PyMuPDF-pro are installed: `pip install PyMuPDF PyMuPDF-pro`. Verify that `import fitz` is executed before attempting to use PyMuPDF-pro specific functions.","cause":"PyMuPDF-pro might not be correctly installed, or `PyMuPDF` (which provides the `fitz` module) is missing, preventing PyMuPDF-pro from patching the `fitz` module.","error":"AttributeError: module 'fitz.utils' has no attribute 'set_license' or AttributeError: module 'fitz' has no attribute 'open_office_document'"},{"fix":"Verify your PyMuPDF-pro license key. Contact Artifex Software support if you suspect the key is invalid or expired. Ensure the key is correctly passed to `fitz.utils.set_license()`.","cause":"The license key provided to `fitz.utils.set_license()` is either incorrect, expired, or has not been properly registered with Artifex Software.","error":"RuntimeError: License key expired or not valid"},{"fix":"Double-check the file path. Ensure the file exists at the specified location and that your application has read permissions for it. Use absolute paths to avoid ambiguity.","cause":"The file path provided to `fitz.open_office_document()` does not point to an existing file, or the path is inaccessible/incorrect.","error":"fitz.EmptyFilename: cannot open path/to/nonexistent.docx"}]}