コード例 #1
0
ファイル: reader.py プロジェクト: jeansch/PyPDF2
 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)
コード例 #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)
コード例 #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
コード例 #4
0
ファイル: writer.py プロジェクト: jeansch/PyPDF2
 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
コード例 #5
0
 def addBlankPage(self, width=None, height=None):
     page = PageObject.createBlankPage(self, width, height)
     self.addPage(page)
     return page
コード例 #6
0
ファイル: writer.py プロジェクト: jeansch/PyPDF2
 def addBlankPage(self, width=None, height=None):
     page = PageObject.createBlankPage(self, width, height)
     self.addPage(page)
     return page