python - PyPDF2 - manually adding new page to merged PDF offsets original bookmark destinations -


the code below works great on i'm trying accomplish. however, if try manually add new first page , bookmark pdf existing bookmark destinations move 1 page , not linked merged.

any suggestions? there way lock bookmark destinations during merge?

import os pypdf2 import pdffilemerger ... pdf in pdffiles: # merge each pdf single pdf , add bookmarks     name = os.path.splitext(os.path.basename(pdf))[0] # split filename .pdf extension     dp = name.index("$") + 1 # find position of $ sign     bookmarkname = name[dp:].replace("_", " ") # set bookmark name & replace underscores spaces         merger.append(open(os.path.join(cdir,pdf), 'rb'), bookmark=bookmarkname) # add next pdf end of previous & add bookmark name     merger.setpagemode("/useoutlines") # show bookmarks on open  merger.write(open(os.path.join(odir,newname), 'wb')) 


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -