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

Fix viewer.py Adapt page size on the fly if necessary #2492

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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: 16 additions & 1 deletion wx/lib/pdfviewer/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,13 @@ def ShowLoadProgress(self, flag):

# This section is concerned with rendering a sub-set of drawing commands on demand

def CheckPageDimensions(self, width, height):
# for documents with pages of different sizes, adjust it to the maximum
if width > self.pagewidth or height > self.pageheight:
self.pagewidth = max(width, self.pagewidth)
self.pageheight = max(height, self.pageheight)
self.CalculateDimensions ()

def CalculateDimensions(self):
"""
Compute the required buffer sizes to hold the viewed rectangle and
Expand Down Expand Up @@ -506,7 +513,6 @@ def __init__(self, parent, pdf_file):
page = self.pdfdoc.loadPage(0)
self.pagewidth = page.bound().width
self.pageheight = page.bound().height
self.page_rect = page.bound()
self.zoom_error = False #set if memory errors during render

def DrawFile(self, frompage, topage):
Expand All @@ -522,6 +528,10 @@ def RenderPage(self, gc, pageno, scale=1.0):
page = self.pdfdoc.load_page(pageno)
except AttributeError: # old PyMuPDF version
page = self.pdfdoc.loadPage(pageno)

# adapt on the fly document page dimensions if necessary
self.parent.CheckPageDimensions (page.bound().width, page.bound().height)

matrix = fitz.Matrix(scale, scale)
try:
try:
Expand Down Expand Up @@ -593,6 +603,11 @@ def DrawFile(self, frompage, topage):
self.gstate = pdfState() # state is reset with every new page
self.saved_state = []
self.page = self.pdfdoc.getPage(pageno)

# adapt on the fly document page dimensions if necessary
self.parent.CheckPageDimensions(self.page.mediaBox.getUpperRight_x(),
self.page.mediaBox.getUpperRight_y())

numpages_generated += 1
pdf_fonts = self.FetchFonts(self.page)
self.pagedrawings[pageno] = self.ProcessOperators(
Expand Down