GroupDocs.Parser allows extracting metadata (document properties, file information) from various document formats including PDF, Emails, Ebooks, Microsoft Office (Word, PowerPoint, Excel), LibreOffice, and many others.
Prerequisites
GroupDocs.Parser for Python via .NET installed
Sample documents for testing
Understanding of document metadata concepts
Extract metadata from documents
To extract metadata from documents, use the get_metadata() method:
fromgroupdocs.parserimportParser# Create an instance of Parser classwithParser("./sample.pdf")asparser:# Extract metadata from the documentmetadata=parser.get_metadata()# Check if metadata extraction is supportedifmetadataisNone:print("Metadata extraction isn't supported")else:# Iterate over metadata itemsforiteminmetadata:# Print metadata name and valueprint(f"{item.name}: {item.value}")
The following sample file is used in this example: sample.pdf
Expected behavior: Returns a collection of MetadataItem objects containing document properties such as author, title, creation date, modified date, etc., or None if metadata extraction is not supported.
Common metadata properties
Typical metadata properties include:
author: Document creator
title: Document title
subject: Document subject or description
keywords: Document keywords
created-time: Creation date and time
last-saved-time: Last modification date and time
application: Application used to create the document
Pages: Number of pages (for some formats)
Extract specific metadata fields
To extract and display specific metadata fields:
fromgroupdocs.parserimportParserdefget_metadata_value(metadata,field_name):"""
Get a specific metadata value by field name.
"""foriteminmetadata:ifitem.name.lower()==field_name.lower():returnitem.valuereturnNone# Create an instance of Parser classwithParser("document.docx")asparser:# Extract metadatametadata=parser.get_metadata()ifmetadata:# Convert to list for reusemetadata_list=list(metadata)# Extract specific fields (the names the engine reports)author=get_metadata_value(metadata_list,"author")title=get_metadata_value(metadata_list,"title")created=get_metadata_value(metadata_list,"created-time")modified=get_metadata_value(metadata_list,"last-saved-time")# Print specific metadataprint("Document Information:")print(f" Title: {title}")print(f" Author: {author}")print(f" Created: {created}")print(f" Modified: {modified}")
The following sample file is used in this example: document.docx
Document Information:
Title: Supply Agreement - Northwind Coffee Roasters
Author: Lena Park
Created: 12/15/2025 10:00:00
Modified: 01/12/2026 09:00:00
Expected behavior: Retrieves specific metadata fields by name, making it easy to access commonly used properties.
Export metadata to dictionary
To convert metadata to a Python dictionary:
fromgroupdocs.parserimportParserdefextract_metadata_as_dict(file_path):"""
Extract document metadata as a dictionary.
"""withParser(file_path)asparser:metadata=parser.get_metadata()ifmetadataisNone:returnNone# Convert to dictionarymetadata_dict={}foriteminmetadata:metadata_dict[item.name]=item.valuereturnmetadata_dict# Usagemetadata=extract_metadata_as_dict("report.pdf")ifmetadata:print("Document Metadata:")forkey,valueinmetadata.items():print(f" {key}: {value}")else:print("Metadata extraction not supported")
The following sample file is used in this example: report.pdf
Expected behavior: Returns metadata as a dictionary with field names as keys and field values as values.
Export metadata to JSON
To export metadata to JSON format:
fromgroupdocs.parserimportParserimportjsondefexport_metadata_to_json(file_path,output_file):"""
Extract metadata and save to JSON file.
"""withParser(file_path)asparser:metadata=parser.get_metadata()ifmetadataisNone:print("Metadata extraction not supported")returnFalse# Build metadata dictionarymetadata_dict={'file_path':file_path,'properties':{}}foriteminmetadata:# Convert value to string for JSON serializationvalue=str(item.value)ifitem.valueisnotNoneelseNonemetadata_dict['properties'][item.name]=value# Save to JSONwithopen(output_file,'w',encoding='utf-8')asf:json.dump(metadata_dict,f,indent=2,ensure_ascii=False)print(f"Metadata exported to {output_file}")returnTrue# Usageexport_metadata_to_json("sample.docx","metadata.json")
The following sample file is used in this example: sample.docx
Expected behavior: Creates a JSON file containing all document metadata in a structured format.
Batch metadata extraction
To extract metadata from multiple documents:
fromgroupdocs.parserimportParserimportcsvdefbatch_extract_metadata(file_paths,output_csv):"""
Extract metadata from several documents and save to CSV.
"""results=[]forfile_pathinfile_paths:print(f"Processing: {file_path}")withParser(file_path)asparser:metadata=parser.get_metadata()ifmetadataisNone:print(" Metadata extraction isn't supported for this format")continue# Extract common fieldsmeta_dict={'file_name':file_path}foriteminmetadata:meta_dict[item.name]=item.valueor""results.append(meta_dict)# Save to CSVifresults:# Get all unique field namesall_fields=set()forresultinresults:all_fields.update(result.keys())# Write CSVwithopen(output_csv,'w',newline='',encoding='utf-8')ascsvfile:writer=csv.DictWriter(csvfile,fieldnames=sorted(all_fields))writer.writeheader()writer.writerows(results)print(f"\nExtracted metadata from {len(results)} documents")print(f"Saved to {output_csv}")# Usagebatch_extract_metadata(["sample.pdf","sample.docx","report.pdf"],"metadata_report.csv")
application,application-version,author,category,company,created-time,file_name,keywords,last-author,last-saved-time,manager,revision-number,subject,template,title
Aspose Pty Ltd.,,Amara Osei,,,,sample.pdf,"annual report, wholesale, Autumn Harvest, revenue, logistics",,02/16/2026 12:00:00,,,Annual report and financial summary,,Harbor Lane Provisions - Annual Report 2025
Microsoft Office Word,786432,Lena Park,Back office,Harbor Lane Provisions,12/15/2025 10:00:00,sample.docx,"supply agreement, cof
[TRUNCATED]
Expected behavior: Processes each listed document, extracts metadata, and generates a CSV report.
Metadata comparison
To compare metadata between documents:
fromgroupdocs.parserimportParserdefcompare_metadata(file1,file2):"""
Compare metadata between two documents.
"""defget_metadata_dict(file_path):withParser(file_path)asparser:metadata=parser.get_metadata()ifmetadata:return{item.name:item.valueforiteminmetadata}return{}metadata1=get_metadata_dict(file1)metadata2=get_metadata_dict(file2)# Find common and unique fieldsall_fields=set(metadata1.keys())|set(metadata2.keys())common_fields=set(metadata1.keys())&set(metadata2.keys())print(f"Comparing: {file1} vs {file2}\n")print(f"{'Field':<20}{'File 1':<30}{'File 2':<30}{'Match':<10}")print("-"*95)forfieldinsorted(all_fields):val1=str(metadata1.get(field,"N/A"))[:30]val2=str(metadata2.get(field,"N/A"))[:30]match="Yes"iffieldincommon_fieldsandmetadata1.get(field)==metadata2.get(field)else"No"print(f"{field:<20}{val1:<30}{val2:<30}{match:<10}")# Usagecompare_metadata("version1.docx","version2.docx")
The following sample file is used in this example: version1.docx
The following sample file is used in this example: version2.docx
Comparing: version1.docx vs version2.docx
Field File 1 File 2 Match
-----------------------------------------------------------------------------------------------
application Microsoft Office Word Microsoft Office Word Yes
application-version 786432 786432 Yes
author Lena Park Lena Park
[TRUNCATED]