When you try and nest several bookmarks with the same name, PyPDF2 does not take it into account. Below self-contained python code to test what I mean (you need at have 3 pdf files named a, b and c in the working folder to test it out)
from PyPDF2 import PdfFileReader, PdfFileMerger
def main():
merger = PdfFileMerger()
first_one = True
for file in ["a.pdf", "b.pdf", "c.pdf"]:
print("next row")
reader = PdfFileReader(file)
merger.append(reader)
if first_one:
child = merger.addBookmark(title="blabla", pagenum=1)
first_one = False
else:
child = merger.addBookmark(title="blabla", pagenum=1, parent=child)
merger.write("test.pdf")
if __name__ == "__main__":
main()
I would expect the resulting pdf to have three levels of nested bookmarks
blabla
blabla
blabla
but instead I get
blabla
blabla
blabla
Is there any way to make sure this does not happen ?
EDIT : I have removed the pagenum
variable as I want those 3 bookmarks to point to the same page.