コード例 #1
0
ファイル: writer.py プロジェクト: jeansch/PyPDF2
    def addBookmark(self, title, pagenum, parent=None):
        """
        Add a bookmark to the pdf, using the specified title and pointing at
        the specified page number. A parent can be specified to make this a
        nested bookmark below the parent.
        """
        pageRef = self.getObject(self._pages)['/Kids'][pagenum]
        action = DictionaryObject()
        action.update({NameObject('/D'): ArrayObject([pageRef,
                                                      NameObject('/FitH'),
                                                      NumberObject(826)]),
                       NameObject('/S'): NameObject('/GoTo')})
        actionRef = self._addObject(action)

        outlineRef = self.getOutlineRoot()
        if parent is None:
            parent = outlineRef
        bookmark = TreeObject()
        bookmark.update({NameObject('/A'): actionRef,
                         NameObject('/Title'): createStringObject(title)})
        bookmarkRef = self._addObject(bookmark)

        parent = parent.getObject()
        parent.addChild(bookmarkRef, self)
        return bookmarkRef
コード例 #2
0
    def addBookmark(self, title, pagenum, parent=None):
        """
        Add a bookmark to the pdf, using the specified title and pointing at
        the specified page number. A parent can be specified to make this a
        nested bookmark below the parent.
        """
        pageRef = self.getObject(self._pages)['/Kids'][pagenum]
        action = DictionaryObject()
        action.update({
            NameObject('/D'):
            ArrayObject([pageRef,
                         NameObject('/FitH'),
                         NumberObject(826)]),
            NameObject('/S'):
            NameObject('/GoTo')
        })
        actionRef = self._addObject(action)

        outlineRef = self.getOutlineRoot()
        if parent is None:
            parent = outlineRef
        bookmark = TreeObject()
        bookmark.update({
            NameObject('/A'): actionRef,
            NameObject('/Title'): createStringObject(title)
        })
        bookmarkRef = self._addObject(bookmark)

        parent = parent.getObject()
        parent.addChild(bookmarkRef, self)
        return bookmarkRef
コード例 #3
0
 def getOutlineRoot(self):
     root = self.getObject(self._root)
     if '/Outlines' in root:
         outline = root['/Outlines']
         idnum = self._objects.index(outline) + 1
         outlineRef = IndirectObject(idnum, 0, self)
         assert outlineRef.getObject() == outline
     else:
         outline = TreeObject()
         outline.update({})
         outlineRef = self._addObject(outline)
         root[NameObject('/Outlines')] = outlineRef
     return outline
コード例 #4
0
 def add(self, title, pagenum):
     pageRef = self.pdf.getObject(self.pdf._pages)['/Kids'][pagenum]
     action = DictionaryObject()
     action.update({NameObject('/D'): ArrayObject([pageRef,
                                                   NameObject('/FitH'),
                                                   NumberObject(826)]),
                    NameObject('/S'): NameObject('/GoTo')})
     actionRef = self.pdf._addObject(action)
     bookmark = TreeObject()
     bookmark.update({NameObject('/A'): actionRef,
                      NameObject('/Title'): createStringObject(title)})
     self.pdf._addObject(bookmark)
     self.tree.addChild(bookmark)
コード例 #5
0
ファイル: writer.py プロジェクト: jeansch/PyPDF2
 def getOutlineRoot(self):
     root = self.getObject(self._root)
     if '/Outlines' in root:
         outline = root['/Outlines']
         idnum = self._objects.index(outline) + 1
         outlineRef = IndirectObject(idnum, 0, self)
         assert outlineRef.getObject() == outline
     else:
         outline = TreeObject()
         outline.update({})
         outlineRef = self._addObject(outline)
         root[NameObject('/Outlines')] = outlineRef
     return outline
コード例 #6
0
 def addBookmarkDict(self, bookmark, parent=None):
     bookmarkObj = TreeObject()
     for k, v in bookmark.items():
         bookmarkObj[NameObject(str(k))] = v
     bookmarkObj.update(bookmark)
     if '/A' in bookmark:
         action = DictionaryObject()
         for k, v in bookmark['/A'].items():
             action[NameObject(str(k))] = v
         actionRef = self._addObject(action)
         bookmarkObj['/A'] = actionRef
     bookmarkRef = self._addObject(bookmarkObj)
     outlineRef = self.getOutlineRoot()
     if parent is None:
         parent = outlineRef
     parent = parent.getObject()
     parent.addChild(bookmarkRef, self)
     return bookmarkRef
コード例 #7
0
ファイル: writer.py プロジェクト: jeansch/PyPDF2
 def addBookmarkDict(self, bookmark, parent=None):
     bookmarkObj = TreeObject()
     for k, v in bookmark.items():
         bookmarkObj[NameObject(str(k))] = v
     bookmarkObj.update(bookmark)
     if '/A' in bookmark:
         action = DictionaryObject()
         for k, v in bookmark['/A'].items():
             action[NameObject(str(k))] = v
         actionRef = self._addObject(action)
         bookmarkObj['/A'] = actionRef
     bookmarkRef = self._addObject(bookmarkObj)
     outlineRef = self.getOutlineRoot()
     if parent is None:
         parent = outlineRef
     parent = parent.getObject()
     parent.addChild(bookmarkRef, self)
     return bookmarkRef