Adding a ToC Using a Named Destination #4172
Replies: 1 comment
-
More investigation... I added a call to set_toc_item() to replace the newly added (erroneous) toc entry using the same destination:
The code throws ValueError("bad bookmark dest") error, but the bookmark is in the PDF:
The PDF is not corrupt, it displays fine through Acrobat, named destination is navigable. |
Beta Was this translation helpful? Give feedback.
-
I am trying to add a new entry in the ToC that references an existing named destination, like this:
toc = combined_pdf.get_toc() new_toc = [[1,'Table of Contents',1],[2,'Lvl2-1',0],[2,'Lvl2-2',0],[2,'Lvl2-3',0]] new_link = { 'kind': 4, 'nameddest': 'table_of_contents4'} new_toc.append([3, 'Last Page', -1, new_link]) combined_pdf.set_toc(new_toc, collapse=99)
After I set the ToC, and then print it out I get this:
[[1, 'Table of Contents', 1, {'kind': 1, 'xref': 108, 'page': 0, 'to': Point(72.0, 36.0), 'zoom': 0.0, 'collapse': False}], [2, 'Lvl2-1', 1, {'kind': 1, 'xref': 109, 'page': 0, 'to': Point(72.0, 36.0), 'zoom': 0.0}], [2, 'Lvl2-2', 1, {'kind': 1, 'xref': 110, 'page': 0, 'to': Point(72.0, 36.0), 'zoom': 0.0}], [2, 'Lvl2-3', 1, {'kind': 1, 'xref': 111, 'page': 0, 'to': Point(72.0, 36.0), 'zoom': 0.0, 'collapse': False}], [3, 'Last Page', -1, {'kind': 0, 'xref': 112, 'page': -1, 'zoom': 0.0}]]
You can see the dictionary for the named destination is mangled up. The kind is incorrect and there is no 'nameddest' attribute.
What am I doing wrong?
Beta Was this translation helpful? Give feedback.
All reactions