From 2481a4382efc39316326e9ea9ee581e789a3d6ad Mon Sep 17 00:00:00 2001 From: Charpentier Johan Date: Tue, 21 Dec 2010 09:34:16 +0100 Subject: [PATCH] Permit merges "on bottom" --- pyPdf/pdf.py | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/pyPdf/pdf.py b/pyPdf/pdf.py index bf60d01..dcaf0f4 100644 --- a/pyPdf/pdf.py +++ b/pyPdf/pdf.py @@ -1125,6 +1125,19 @@ def getContents(self): def mergePage(self, page2): self._mergePage(page2) + ## + # Merges the content streams of two pages into one. Resource references + # (i.e. fonts) are maintained from both pages. The mediabox/cropbox/etc + # of this page are not altered. The parameter page's content stream will + # be added to the begin of this page's content stream, meaning that it + # will be drawn before, or "on bottom" of this page. + #

+ # Stability: Added in v1.13, will exist for all future 1.x releases. + # @param page2 An instance of {@link #PageObject PageObject} to be merged + # into this one. + def mergePageBottom(self, page2,): + self._mergePage(page2, onbottom=True) + ## # Actually merges the content streams of two pages into one. Resource # references (i.e. fonts) are maintained from both pages. The @@ -1139,7 +1152,10 @@ def mergePage(self, page2): # contents stream. Must return: new contents # stream. If omitted, the content stream will # not be modified. - def _mergePage(self, page2, page2transformation=None): + # @param onbottom A boolean to permit merge content stream before original + # page content, meaning that it will be drawn before, or + # "on bottom" of this page. + def _mergePage(self, page2, page2transformation=None, onbottom=False): # First we work on merging the resource dictionaries. This allows us # to find out what symbols in the content streams we might need to # rename. @@ -1165,7 +1181,7 @@ def _mergePage(self, page2, page2transformation=None): newContentArray = ArrayObject() originalContent = self.getContents() - if originalContent is not None: + if originalContent is not None and not onbottom: newContentArray.append(PageObject._pushPopGS( originalContent, self.pdf)) @@ -1178,6 +1194,11 @@ def _mergePage(self, page2, page2transformation=None): page2Content = PageObject._pushPopGS(page2Content, self.pdf) newContentArray.append(page2Content) + # Permit to merge "on bottom" + if originalContent is not None and onbottom: + newContentArray.append(PageObject._pushPopGS( + originalContent, self.pdf)) + self[NameObject('/Contents')] = ContentStream(newContentArray, self.pdf) self[NameObject('/Resources')] = newResources