Skip to content

Instantly share code, notes, and snippets.

@harajune
Last active May 21, 2022 02:07
Show Gist options
  • Save harajune/04e762898c71c0d07ec2226e31b96be1 to your computer and use it in GitHub Desktop.
Save harajune/04e762898c71c0d07ec2226e31b96be1 to your computer and use it in GitHub Desktop.
class Pdf:
def __init__(self, pdfParameter):
self._pdfParameter = pdfParameter
self._currentPage = 0
@property
def fileObject(self):
return self._fileObject
@property
def currentPage(self):
return self._currentPage
@property
def numOfPages(self):
return self._numOfPages
def load(self):
self._fileObject = open(self._pdfParameter.filename, "rb")
self._numOfPages = PdfFileReader(self._fileObject).getNumPages()
# client has to call next() first.
# the page number begins with 0
if self._pdfParameter.reverse:
self._currentPage = self._numOfPages
else:
self._currentPage = -1
def next(self):
if self._pdfParameter.reverse:
self._currentPage = self._currentPage - 1
else:
self._currentPage = self._currentPage + 1
if self._currentPage < 0 or self._currentPage >= self._numOfPages:
return False
return True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment