[Python] Add a bookmark to a PDF with PyPDF2

Discussão em 'Python' iniciado por Stack, Junho 13, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to add a bookmark to a PDF using PyPDF2. I run the following with no problems. But a bookmark is never created. Any thoughts on what I'm doing wrong. The PDF is 2 pages long.

    from PyPDF2 import PdfFileReader, PdfFileWriter

    reader = PdfFileReader("test.pdf") # open input
    writer = PdfFileWriter() # open output
    writer.addPage(reader.getPage(0)) # insert page
    writer.addBookmark("Hello, World Bookmark", 0, parent=None) # add bookmark

    Continue reading...

Compartilhe esta Página