Skip to content

Commit

Permalink
Merge branch 'master' of github.com:NextThought/z3c.rml into NextThou…
Browse files Browse the repository at this point in the history
…ght-master
  • Loading branch information
strichter committed Dec 5, 2013
2 parents fdac55a + e50a63e commit bac89b2
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 16 deletions.
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ CHANGES
2.3.2 (unreleased)
------------------

- Nothing changed yet.
- Switch from ``pyPdf`` to the newer ``PyPDF2`` library.


2.3.1 (2013-12-03)
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def alltests():
install_requires=[
'Pygments',
'lxml',
'pyPdf',
'PyPDF2',
'reportlab',
'setuptools',
'svg2rlg',
Expand All @@ -95,4 +95,3 @@ def alltests():
include_package_data=True,
zip_safe=False,
)

14 changes: 7 additions & 7 deletions src/z3c/rml/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,28 @@
from z3c.rml import attr, directive, interfaces

try:
import pyPdf
from pyPdf.generic import NameObject
import PyPDF2
from PyPDF2.generic import NameObject
except ImportError:
# We don't want to require pyPdf, if you do not want to use the features
# in this module.
pyPdf = None
PyPDF2 = None

class MergePostProcessor(object):

def __init__(self):
self.operations = {}

def process(self, inputFile1):
input1 = pyPdf.PdfFileReader(inputFile1)
output = pyPdf.PdfFileWriter()
input1 = PyPDF2.PdfFileReader(inputFile1)
output = PyPDF2.PdfFileWriter()
output._info.getObject().update(input1.documentInfo)
output._root.getObject()[NameObject("/Outlines")] = (
output._addObject(input1.trailer["/Root"]["/Outlines"]))
for (num, page) in enumerate(input1.pages):
if num in self.operations:
for mergeFile, mergeNumber in self.operations[num]:
merger = pyPdf.PdfFileReader(mergeFile)
merger = PyPDF2.PdfFileReader(mergeFile)
mergerPage = merger.getPage(mergeNumber)
mergerPage.mergePage(page)
page = mergerPage
Expand Down Expand Up @@ -76,7 +76,7 @@ def getProcessor(self):
return procs['MERGE']

def process(self):
if pyPdf is None:
if PyPDF2 is None:
raise Exception(
'pyPdf is not installed, so this feature is not available.')
inputFile, inPage = self.getAttributeValues(valuesOnly=True)
Expand Down
10 changes: 5 additions & 5 deletions src/z3c/rml/pdfinclude.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
"""
__docformat__ = "reStructuredText"
try:
import pyPdf
import PyPDF2
except ImportError:
pyPdf = None
PyPDF2 = None
from reportlab.platypus import flowables

from z3c.rml import attr, flowable, interfaces, occurence, page
Expand All @@ -30,7 +30,7 @@ def __init__(self, pdf_file, pages, mergeprocessor):
self.pdf_file = pdf_file
self.proc = mergeprocessor

pdf = pyPdf.PdfFileReader(pdf_file)
pdf = PyPDF2.PdfFileReader(pdf_file)
self.num_pages = pdf.getNumPages()
self.pages = pages if pages else range(1, self.num_pages+1)

Expand Down Expand Up @@ -96,9 +96,9 @@ def getProcessor(self):
return procs['MERGE']

def process(self):
if pyPdf is None:
if PyPDF2 is None:
raise Exception(
'pyPdf is not installed, so this feature is not available.')
'PyPDF2 is not installed, so this feature is not available.')
args = dict(self.getAttributeValues())
proc = self.getProcessor()
self.parent.flow.append(
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ deps =
Pygments
coverage
lxml
pyPdf
PyPDF2
reportlab
setuptools
svg2rlg
Expand Down

0 comments on commit bac89b2

Please sign in to comment.