Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save documentprocessing/d50b9c82380d27dbeae78602dd10c721 to your computer and use it in GitHub Desktop.
Save documentprocessing/d50b9c82380d27dbeae78602dd10c721 to your computer and use it in GitHub Desktop.
Write PDF metadata with PikePDF API for Python
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