Clear PDF Metadata

Contents
[ ]

PDF often contain metadata such as title, author, keywords, creation dates, and custom fields. In some scenarios, you may want to remove all metadata from a PDF, for example before distribution or archival. Aspose.PDF provides the clear_info() method to remove all metadata easily. After clearing, you can save the PDF using the save() method.

  1. Load the PDF file.
  2. Clear all metadata.
  3. Save the clean PDF.
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 clear_pdf_metadata(infile, outfile):

    # Get PDF information
    pdf_info = pdf_facades.PdfFileInfo(infile)

    # Clear PDF metadata
    pdf_info.clear_info()

    # Save updated metadata
    pdf_info.save(outfile)