Как указать закладку на заголовок в PyPDF2?

#python #pdf #bookmarks #pypdf2

Вопрос:

 from PyPDF2 import PdfFileWriter, PdfFileReader
from PyPDF2.generic import RectangleObject

output = PdfFileWriter() # open output
input = PdfFileReader(open('result.pdf', 'rb')) # open input
output.addPage(input.getPage(0)) # insert page
output.addPage(input.getPage(1))
parent = output.addBookmark('Introduction', 1) # add parent bookmark, like could be mapped to a heading
output.addBookmark('yoyoy', 1, parent) # add bookmark
output.setPageMode("/UseOutlines") #This is what tells the PDF to open to bookmarks
outputStream = open('result_2.0.pdf','wb') #creating result pdf JCT
output.write(outputStream) #writing to result pdf JCT
outputStream.close() #closing result 
#final code for bookmark
 

Как и в реальном pdf-файле, мы связываем закладки с заголовками, и подзаголовки могут сделать то же самое и здесь, заранее спасибо