Metadata redactions

With GroupDocs.Redaction API you can apply metadata redactions for documents of different formats like PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX and others. See full list at supported document formats article.

GroupDocs.Redactions provides a flexible API that allows to replace or remove metadata using filters or search by regular expression.

Filter metadata

Base functionality for all redactions, derived from MetadataRedaction base class is metadata filtering and it is mandatory for metadata redactions. It uses flagged enumeration MetadataFilters, containing items for most frequent metadata entries. You can set the filter to All, or any combination of metadata. For instance, the example below sets filter to Author, Manager and NameOfApplication - for textual redaction or cleaning them out:

# redaction derived from MetadataRedaction
redaction.filter = MetadataFilters.AUTHOR | MetadataFilters.MANAGER | MetadataFilters.NAME_OF_APPLICATION

Below is the table with full list of MetadataFilters items:

FilterNumeric valueDescription
None0Empty filter setting, matches no metadata items
Author1Author of the document
Category2Category of the document
Comments4Document comment
Company8Company of the Author
ContentStatus16Content status
CreatedTime32Created time
HyperlinkBase64Hyperlink base
LastPrinted128Last printed date and time
LastSavedBy256Last saved by user
LastSavedTime1024Last saved date and time
NameOfApplication2048Name of application where the document was created
Manager4096Author’s manager name
RevisionNumber8192Revision number
Subject16384Subject of the document
Template32768Document template name
Title65536Document title
TotalEditingTime131072Total editing time
Version262144Document’s version
Description524288Document’s description
Keywords1048576Document’s keywords
ContentType2097152Content type
All2147483647All types of the metadata items

Clean metadata

You can replace all or specific metadata in the document with empty (blank or minimal) values using EraseMetadataRedaction class. The example below blanks out all properties of the document:

from groupdocs.redaction import Redactor
from groupdocs.redaction.options import SaveOptions
from groupdocs.redaction.redactions import EraseMetadataRedaction, MetadataFilters


def clean_all_metadata():
    # Specify the redaction options to erase all metadata
    met_red = EraseMetadataRedaction(MetadataFilters.ALL)

    # Load the document to be redacted
    with Redactor("./sample.docx") as redactor:
        # Apply the redaction
        result = redactor.apply(met_red)

        # Save the redacted document next to the source file
        so = SaveOptions()
        so.add_suffix = True
        so.rasterize_to_pdf = False
        so.redacted_file_suffix = "redacted"
        redactor.save(so)


if __name__ == "__main__":
    clean_all_metadata()

sample.docx is the sample file used in this example. Click here to download it.

Binary file (DOCX, 16 KB)

Download full output

You can specify MetadataFilter.All or use default constructor to blank out all metadata within given document, Custom - to clear all custom metadata entries.

Redact metadata

You can use MetadataSearchRedaction to remove sensitive data from document’s metadata using regular expressions. For instance, we can remove any mention of “Company Ltd.”:

from groupdocs.redaction import Redactor
from groupdocs.redaction.options import SaveOptions
from groupdocs.redaction.redactions import MetadataSearchRedaction


def redact_metadata():
    # Specify the redaction options: search pattern and replacement string
    met_red = MetadataSearchRedaction("Company Ltd.", "--company--")

    # Load the document to be redacted
    with Redactor("./sample.docx") as redactor:
        # Apply the redaction
        result = redactor.apply(met_red)

        # Save the redacted document next to the source file
        so = SaveOptions()
        so.add_suffix = True
        so.rasterize_to_pdf = False
        so.redacted_file_suffix = "redacted"
        redactor.save(so)


if __name__ == "__main__":
    redact_metadata()

sample.docx is the sample file used in this example. Click here to download it.

Binary file (DOCX, 16 KB)

Download full output

First argument is regular expression, second is a replacement string. You can also set scope for redaction by setting filter, e.g. to MetadataFilter.Company. - it will leave the regular expressions matches undone in all metadata items, except “Company” property:

from groupdocs.redaction import Redactor
from groupdocs.redaction.options import SaveOptions
from groupdocs.redaction.redactions import MetadataSearchRedaction, MetadataFilters


def redact_metadata_with_filter():
    # Specify the redaction options: search pattern and replacement string
    met_red = MetadataSearchRedaction("Company Ltd.", "--company--")

    # Limit the redaction scope to the Company metadata item only
    met_red.filter = MetadataFilters.COMPANY

    # Load the document to be redacted
    with Redactor("./sample.docx") as redactor:
        # Apply the redaction
        result = redactor.apply(met_red)

        # Save the redacted document next to the source file
        so = SaveOptions()
        so.add_suffix = True
        so.rasterize_to_pdf = False
        so.redacted_file_suffix = "redacted"
        redactor.save(so)


if __name__ == "__main__":
    redact_metadata_with_filter()

sample.docx is the sample file used in this example. Click here to download it.

Binary file (DOCX, 16 KB)

Download full output

Metadata redaction status

All metadata redactions apply to each metadata item separately, and even if metadata item redaction fails, the rest of the metadata items will be updated. You can find a list of failed, skipped (rejected) metadata items and reasons for that in ErrorMessage property of RedactorLogEntry.Result.