Skip to content

Commit

Permalink
Merge pull request #2609 from Infernio/inf-pymupdf-import
Browse files Browse the repository at this point in the history
pdfviewer: Add support for pymupdf renaming
  • Loading branch information
swt2c committed Sep 13, 2024
2 parents 99d1749 + 6dd4312 commit b2733b5
Showing 1 changed file with 10 additions and 7 deletions.
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

0 comments on commit b2733b5

Please sign in to comment.