Esempio n. 1
0
 def _flatten(self, pages=None, inherit=None, indirectRef=None):
     inheritablePageAttributes = (NameObject("/Resources"),
                                  NameObject("/MediaBox"),
                                  NameObject("/CropBox"),
                                  NameObject("/Rotate"))
     if inherit is None:
         inherit = dict()
     if pages is None:
         self.flattenedPages = []
         catalog = self.trailer["/Root"].getObject()
         pages = catalog["/Pages"].getObject()
     t = pages["/Type"]
     if t == "/Pages":
         for attr in inheritablePageAttributes:
             if attr in pages:
                 inherit[attr] = pages[attr]
         for page in pages["/Kids"]:
             addt = {}
             if isinstance(page, IndirectObject):
                 addt["indirectRef"] = page
             self._flatten(page.getObject(), inherit, **addt)
     elif t == "/Page":
         for attr, value in inherit.items():
             # if the page has it's own value, it does not inherit the
             # parent's value:
             if attr not in pages:
                 pages[attr] = value
         pageObj = PageObject(self, indirectRef)
         pageObj.update(pages)
         self.flattenedPages.append(pageObj)
Esempio n. 2
0
 def _flatten(self, pages=None, inherit=None, indirectRef=None):
     inheritablePageAttributes = (NameObject("/Resources"),
                                  NameObject("/MediaBox"),
                                  NameObject("/CropBox"),
                                  NameObject("/Rotate"))
     if inherit is None:
         inherit = dict()
     if pages is None:
         self.flattenedPages = []
         catalog = self.trailer["/Root"].getObject()
         pages = catalog["/Pages"].getObject()
     t = pages["/Type"]
     if t == "/Pages":
         for attr in inheritablePageAttributes:
             if attr in pages:
                 inherit[attr] = pages[attr]
         for page in pages["/Kids"]:
             addt = {}
             if isinstance(page, IndirectObject):
                 addt["indirectRef"] = page
             self._flatten(page.getObject(), inherit, **addt)
     elif t == "/Page":
         for attr, value in inherit.items():
             # if the page has it's own value, it does not inherit the
             # parent's value:
             if attr not in pages:
                 pages[attr] = value
         pageObj = PageObject(self, indirectRef)
         pageObj.update(pages)
         self.flattenedPages.append(pageObj)
Esempio n. 3
0
 def insertBlankPage(self, width=None, height=None, index=0):
     if width is None or height is None and \
             (self.getNumPages() - 1) >= index:
         oldpage = self.getPage(index)
         width = oldpage.mediaBox.getWidth()
         height = oldpage.mediaBox.getHeight()
     page = PageObject.createBlankPage(self, width, height)
     self.insertPage(page, index)
     return page
Esempio n. 4
0
 def insertBlankPage(self, width=None, height=None, index=0):
     if width is None or height is None and \
             (self.getNumPages() - 1) >= index:
         oldpage = self.getPage(index)
         width = oldpage.mediaBox.getWidth()
         height = oldpage.mediaBox.getHeight()
     page = PageObject.createBlankPage(self, width, height)
     self.insertPage(page, index)
     return page
Esempio n. 5
0
 def addBlankPage(self, width=None, height=None):
     page = PageObject.createBlankPage(self, width, height)
     self.addPage(page)
     return page
Esempio n. 6
0
 def addBlankPage(self, width=None, height=None):
     page = PageObject.createBlankPage(self, width, height)
     self.addPage(page)
     return page