-
The problem: I have a PDF file with nested bookmarks. When I process it, I lose the bookmarks. I want to save the nested bookmark information before processing, and then put in the same bookmarks after processing. What I've done: I looked at the documentation, and source code. I started playing around with it, and realized that PdfReader's outline property gives me a nested list of dictionary for outline item and list for nesting of outline items. I tried using PdfWriter's add_outline_item_dict and couple other methods. Unfortunately, I get an error - it seems like I can can only give it one outline item at a time. So I was thinking maybe I need to write my own function. But before doing that I wanted to browse the code a bit to see if I can avoid reinventing the wheel. I downloaded github desktop etc. etc. and now I am here. Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
Normally if you are using use |
Beta Was this translation helpful? Give feedback.
-
def p(a, pref=""):
if isinstance(a, list):
for aa in a:
p(aa, pref + " ")
else:
print(pref + a["/Title"])
p(r.outline) The dict will provide you with all the required fields. Also |
Beta Was this translation helpful? Give feedback.
-
can pypdf export the destination point (position on target page) of bookmarks? for example, the https://pymupdf.readthedocs.io/en/latest/document.html#Document.get_toc |
Beta Was this translation helpful? Give feedback.
Normally if you are using use
append()
withimport_outline=True
you should keep all the outlines that applies to the imported pages. have you tried it?