Last active
August 1, 2025 07:40
-
-
Save rnjailamba/fa7ba786306b6fa6aadfde23c0e9a31f to your computer and use it in GitHub Desktop.
Update table of contents and metadata of PDF with pymupdf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pymupdf | |
doc = pymupdf.open("book.pdf") | |
#metadata = doc.metadata | |
#new_metadata = {"title": "New Title", "author": "New Author"} | |
#new_metadata = metadata | |
#doc.set_metadata(new_metadata) | |
toc = doc.get_toc() | |
new_toc = toc | |
doc.set_toc(new_toc) | |
toc = doc.get_toc() | |
print(toc) | |
doc.save(doc.name, incremental=True, encryption=pymupdf.PDF_ENCRYPT_KEEP) | |
doc.close() | |
#https://medium.com/@pymupdf/mastering-metadata-and-table-of-contents-manipulation-with-pymupdf-b9099b64b17b |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment