I am trying to create bookmark in pdf based on keyword present in pdf file. I can create the bookmark for pages in pdf using pypdf2's addbookmark function. but it is page based, not keyword based. For example, if pdf contains 'metadata' as a word, I would like to create bookmark for 'metadata' keyword.
I have referred Add a bookmark to a PDF with PyPDF2 which creates bookmark for pages.
output = PdfFileWriter() # open output
input = PdfFileReader(open('test.pdf', 'rb')) # open input
output.addPage(input.getPage(0)) # insert page
output.addBookmark('Hello, World Bookmark', 0, parent=None) # add bookmark
outputStream = file('result.pdf','wb') #creating result pdf JCT
output.write(outputStream) #writing to result pdf JCT
outputStream.close() #closing result JCT