Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pdfviewer: Add support for pymupdf renaming #2609

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions wx/lib/pdfviewer/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@

try:
# see http://pythonhosted.org/PyMuPDF - documentation & installation
import fitz
try:
import pymupdf
except ImportError:
import fitz as pymupdf
mupdf = True
if VERBOSE: print('pdfviewer using PyMuPDF (GPL)')
except ImportError:
Expand Down Expand Up @@ -474,7 +477,7 @@ class mupdfProcessor(object):
"""
Create an instance of this class to open a PDF file, process the contents of
each page and render each one on demand using the GPL mupdf library, which is
accessed via the python-fitz package bindings (version 1.9.1 or later)
accessed via the pymupdf package bindings (version 1.9.1 or later)
"""
def __init__(self, parent, pdf_file):
"""
Expand All @@ -484,17 +487,17 @@ def __init__(self, parent, pdf_file):
"""
self.parent = parent
if isinstance(pdf_file, string_types):
# a filename/path string, pass the name to fitz.open
# a filename/path string, pass the name to pymupdf.open
pathname = pdf_file
self.pdfdoc = fitz.open(pathname)
self.pdfdoc = pymupdf.open(pathname)
else:
# assume it is a file-like object, pass the stream content to fitz.open
# assume it is a file-like object, pass the stream content to pymupdf.open
# and a '.pdf' extension in pathname to identify the stream type
pathname = 'fileobject.pdf'
if pdf_file.tell() > 0: # not positioned at start
pdf_file.seek(0)
stream = bytearray(pdf_file.read())
self.pdfdoc = fitz.open(pathname, stream)
self.pdfdoc = pymupdf.open(pathname, stream)

try:
self.numpages = self.pdfdoc.page_count
Expand Down Expand Up @@ -522,7 +525,7 @@ def RenderPage(self, gc, pageno, scale=1.0):
page = self.pdfdoc.load_page(pageno)
except AttributeError: # old PyMuPDF version
page = self.pdfdoc.loadPage(pageno)
matrix = fitz.Matrix(scale, scale)
matrix = pymupdf.Matrix(scale, scale)
try:
try:
# MUST be keyword arg(s)
Expand Down