There are 2 questions:
- I want to add the sub-bookmark to an existing bookmark. What I know is just to add first-layer bookmark.
- I want to know how to remain the existing bookmark to avoid delete an existing bookmark for the second run.
This is the code I tried:
from pypdf import PdfReader, PdfWriter
reader = PdfReader("updated_examplefile.pdf")
writer = PdfWriter()
# Copy all pages from the reader to the writer
for page in reader.pages:
writer.add_page(page)
# Update the outline
writer.add_outline_item(title="sample chapter 1", page_number= 2)
writer.add_outline_item(title="sample chapter 2", page_number= 60)
writer.add_outline_item(title="sample chapter 3", page_number= 140)
# Update PDF
with open("updated_examplefile.pdf", "wb") as f:
writer.write(f)
I add three bookmarks to “updated_examplefile.pdf”. But the bookmarks will be refreshed on every run. I want to keep the bookmark for first run on the second run.
These bookmarks are just one layer. How to add sub-bookmark to them?
New contributor
Spring Harbor is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.