How to Change PDF Metadata using Python

This quick topic will mentor you in how to change PDF metadata using Python. It has details for setting the development environment to run the sample application, a list of programming steps for the feature implementation and a runnable sample code to modify PDF metadata using Python. Other properties that can be modified other than the attached sample code will also be discussed.

Steps to Edit PDF Properties using Python

  1. Set the IDE to use Aspose.PDF for Python via .NET to edit metadata
  2. Load the PDF file using the Document class object to modify file properties
  3. Access the PDF file metadata using the DocumentInfo class object
  4. Update the desired properties using the accessed document info object
  5. Save the resultant PDF file with edited metadata

These steps outline the process to edit metadata of PDF using Python. The process is commenced by loading the PDF file and accessing the file properties using the DocumentInfo in the aspose.pdf namespace. Using this object, a few properties are updated by setting new values before saving the resultant PDF file on the disk.

Code to Change PDF Properties using Python

The aforementioned sample code demonstrate the development of a simple PDF metadata editor using Python. You may update any properties for instance title, subject, keywords, creation_time_zone, mod_time_zone, and mod_date. You may add new properties using the add(key, value) and remove a property using the remove(key) method.

The article has taught us to change metadata of PDF using Python. If you want to learn the process to get images from a PDF file, refer to the article on how to get images from a PDF in Python.