Exemple #1
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
Exemple #2
0
 def __init__(self):
     self._header = b_("%PDF-1.3")
     self._objects = []  # array of indirect objects
     # The root of our page tree node.
     pages = DictionaryObject()
     pages.update({
         NameObject("/Type"): NameObject("/Pages"),
         NameObject("/Count"): NumberObject(0),
         NameObject("/Kids"): ArrayObject()
     })
     self._pages = self._addObject(pages)
     # info object
     info = DictionaryObject()
     info.update({
         NameObject("/Producer"):
         createStringObject(
             u"Python PDF Library - http://pybrary.net/pyPdf/")
     })
     self._info = self._addObject(info)
     # root object
     root = DictionaryObject()
     root.update({
         NameObject("/Type"): NameObject("/Catalog"),
         NameObject("/Pages"): self._pages
     })
     self._root = self._addObject(root)
Exemple #3
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
Exemple #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)
Exemple #5
0
 def _decryptObject(self, obj, key):
     if isinstance(obj, ByteStringObject) \
             or isinstance(obj, TextStringObject):
         obj = createStringObject(utils.RC4_encrypt(key,
                                                    obj.original_bytes))
     elif isinstance(obj, StreamObject):
         obj._data = utils.RC4_encrypt(key, obj._data)
     elif isinstance(obj, DictionaryObject):
         for dictkey, value in obj.items():
             obj[dictkey] = self._decryptObject(value, key)
     elif isinstance(obj, ArrayObject):
         for i in range(len(obj)):
             obj[i] = self._decryptObject(obj[i], key)
     return obj
Exemple #6
0
 def _decryptObject(self, obj, key):
     if isinstance(obj, ByteStringObject) \
             or isinstance(obj, TextStringObject):
         obj = createStringObject(utils.RC4_encrypt(key,
                                                    obj.original_bytes))
     elif isinstance(obj, StreamObject):
         obj._data = utils.RC4_encrypt(key, obj._data)
     elif isinstance(obj, DictionaryObject):
         for dictkey, value in obj.items():
             obj[dictkey] = self._decryptObject(value, key)
     elif isinstance(obj, ArrayObject):
         for i in range(len(obj)):
             obj[i] = self._decryptObject(obj[i], key)
     return obj
Exemple #7
0
 def __init__(self):
     self._header = b_("%PDF-1.3")
     self._objects = []  # array of indirect objects
     # The root of our page tree node.
     pages = DictionaryObject()
     pages.update({NameObject("/Type"): NameObject("/Pages"),
                   NameObject("/Count"): NumberObject(0),
                   NameObject("/Kids"): ArrayObject()})
     self._pages = self._addObject(pages)
     # info object
     info = DictionaryObject()
     info.update({NameObject("/Producer"): createStringObject(
         u"Python PDF Library - http://pybrary.net/pyPdf/")})
     self._info = self._addObject(info)
     # root object
     root = DictionaryObject()
     root.update({NameObject("/Type"): NameObject("/Catalog"),
                  NameObject("/Pages"): self._pages})
     self._root = self._addObject(root)