распечатать pdf дерево закладок - PYPDF2 - PullRequest
0 голосов
/ 20 апреля 2020

Я пытаюсь напечатать дерево закладок в формате pdf, но не знаю, почему ничего не печатается. когда я произвожу следующий код, который у меня есть: Процесс завершен с кодом завершения 0, но ничего не печатается в консоли.

любая помощь? Спасибо

from PyPDF2 import PdfFileReader
from PyPDF2.pdf import Destination
# Read the pdf file
reader = PdfFileReader(r'C:\Users\xxxx\Desktop\document1.pdf')
outlines = reader.outlines


class DestinationNode(object):
    def __init__(self, heading, parent=None):
       self.heading = heading
       self.parent = parent
       self.children = []

    def add_child(self, child):
        self.children.append(child)

   def construct_outline_tree(self):

         # Find child destination
        def find_destination(nested_dest):
           destinations = []
           for obj in nested_dest:
           if isinstance(obj, Destination):
              destinations.append(obj)
              return destinations
      # Generate the outline tree and return its root node
      def generate_tree(parent, nested_dest):
        destinations = find_destination(nested_dest)
        sub_nested_dict = {}

        for dest in destinations:
          new_node = DestinationNode(dest.title, parent=parent)
          parent.add_child(new_node)
          next_idx = nested.index(dest)+ 1
          if next_idx < len(nested_dest) - 1 and isinstance(nested_dest[next_idx, list]):
             sub_nested_dict[new_node] = nested_dest[next_idx]
          for subroot, sub_nested in sub_nested_dict.iteritems():
             generate_tree(reader, subroot, sub_nested)
            # Create a fake root as an entrance

           root = DestinationNode('Root')

     generate_tree(root, outlines)
     return(root)
...