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
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
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
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)
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