/usr/share/pyshared/z3c/rml/page.py is in python-z3c.rml 2.0.0-0ubuntu3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | ##############################################################################
#
# Copyright (c) 2007 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Page Drawing Related Element Processing
$Id: page.py 73806 2007-03-28 03:11:03Z srichter $
"""
__docformat__ = "reStructuredText"
import cStringIO
from z3c.rml import attr, directive, interfaces
try:
import pyPdf
except ImportError:
# We don't want to require pyPdf, if you do not want to use the features
# in this module.
pyPdf = None
class MergePostProcessor(object):
def __init__(self):
self.operations = {}
def process(self, inputFile1):
input1 = pyPdf.PdfFileReader(inputFile1)
output = pyPdf.PdfFileWriter()
for (num, page) in enumerate(input1.pages):
if num in self.operations:
for mergeFile, mergeNumber in self.operations[num]:
merger = pyPdf.PdfFileReader(mergeFile)
mergerPage = merger.getPage(mergeNumber)
mergerPage.mergePage(page)
page = mergerPage
output.addPage(page)
outputFile = cStringIO.StringIO()
output.write(outputFile)
return outputFile
class IMergePage(interfaces.IRMLDirectiveSignature):
"""Merges an existing PDF Page into the one to be generated."""
filename = attr.File(
title=u'File',
description=(u'Reference to the PDF file to extract the page from.'),
required=True)
page = attr.Integer(
title=u'Page Number',
description=u'The page number of the PDF file that is used to merge..',
required=True)
class MergePage(directive.RMLDirective):
signature = IMergePage
def getProcessor(self):
manager = attr.getManager(self, interfaces.IPostProcessorManager)
procs = dict(manager.postProcessors)
if 'MERGE' not in procs:
proc = MergePostProcessor()
manager.postProcessors.append(('MERGE', proc))
return proc
return procs['MERGE']
def process(self):
if pyPdf is None:
raise Exception(
'pyPdf is not installed, so this feature is not available.')
inputFile, inPage = self.getAttributeValues(valuesOnly=True)
manager = attr.getManager(self, interfaces.ICanvasManager)
outPage = manager.canvas.getPageNumber()-1
proc = self.getProcessor()
pageOperations = proc.operations.setdefault(outPage, [])
pageOperations.append((inputFile, inPage))
|