Created
January 14, 2025 15:02
-
-
Save documentprocessing/d50b9c82380d27dbeae78602dd10c721 to your computer and use it in GitHub Desktop.
Write PDF metadata with PikePDF API for Python
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 pikepdf | |
# Load the PDF file | |
file_path = "example.pdf" | |
output_path = "updated_example.pdf" | |
with pikepdf.Pdf.open(file_path) as pdf: | |
# Access the document metadata | |
metadata = pdf.docinfo | |
# Update metadata fields | |
metadata["/Title"] = "Updated PDF Title" | |
metadata["/Author"] = "Jane Doe" | |
metadata["/Subject"] = "Metadata Update Example" | |
metadata["/Keywords"] = "PDF, PikePDF, Metadata, Example" | |
# Save the updated PDF to a new file | |
pdf.save(output_path) | |
print("Metadata updated successfully!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment