Set PDF Metadata
Contents
[
Hide
]
PDF documents can contain both standard metadata (Title, Subject, Keywords, Creator, Author) and custom metadata stored as XMP properties. Aspose.PDF provides a simple API to modify these properties in Python. This guide covers how to update these fields and save the modified PDF file using the PdfFileInfo class.
- Load the PDF file.
- Update standard metadata.
- Add or update custom metadata.
- Save updated metadata.
import aspose.pdf as ap
import aspose.pdf.facades as pdf_facades
from io import FileIO
import sys
from os import path
sys.path.append(path.join(path.dirname(__file__), ".."))
from config import set_license, initialize_data_dir
def set_pdf_metadata(infile, outfile):
# Get PDF information
pdf_info = pdf_facades.PdfFileInfo(infile)
# Set PDF metadata
pdf_info.subject = "Aspose PDF for Python via .NET"
pdf_info.title = "Aspose PDF for Python via .NET"
pdf_info.keywords = "Aspose, PDF, Python, .NET"
pdf_info.creator = "Aspose Team"
pdf_info.set_meta_info("CustomKey", "CustomValue")
# pdf_info.save_new_info(outfile)
# Is obsolete, use save() method instead
# Save updated metadata
pdf_info.save(outfile)