View and Update Metadata of PDF, Microsoft Word, Powerpoint and Excel Spreadsheets via Python applications.
Last active
November 12, 2023 16:51
Manage Document Metadata using Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
docMetadata = aw.Document(my_dir + "Properties.docx") | |
customProperties = docMetadata.custom_document_properties | |
if (customProperties.get_by_name("Authorized") != None) : | |
return | |
customProperties.add("Authorized", True) | |
customProperties.add("Authorized By", "John Smith") | |
customProperties.add("Authorized Date", datetime.today()) | |
customProperties.add("Authorized Revision", doc.built_in_document_properties.revision_number) | |
customProperties.add("Authorized Amount", 123.45) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import aspose.pdf as ap | |
pdf_document = ap.Document(DIR_INPUT_METADATA + "GetFileInfo.pdf") | |
doc_info = pdf_document.info | |
print("Author :", doc_info.author) | |
print("Creation Date :", doc_info.creation_date) | |
print("Keywords :", doc_info.keywords) | |
print("Modify Date :", doc_info.mod_date) | |
print("Subject :", doc_info.subject) | |
print("Title :", doc_info.title) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import aspose.pdf as pdf | |
import datetime | |
pdfDoc = pdf.Document("input.pdf") | |
meta = pdf.DocumentInfo(pdfDoc) | |
meta.creator = "Creator Info" | |
meta.producer = "Producer Info" | |
meta.trapped = 'True' | |
meta.author = "Author info" | |
meta.creation_date = datetime.datetime.now() | |
pdfDoc.save("UpdatedMeta.pdf") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
wkb = self.Workbook(self.dataDir + "Book1.xls") | |
customProperties = wkb.getWorksheets().getCustomDocumentProperties() | |
#customProperty1 = customProperties.get(3) | |
customProperty2 = customProperties.get("Owner") | |
publisher = customProperties.add("Publisher", "Aspose") | |
wkb.save(self.dataDir + "Test_Workbook.xls") | |
customProperties.remove("Publisher") | |
wkb.save(dataDir + "Test_Workbook_RemovedProperty.xls") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import aspose.slides as slides | |
with slides.Presentation(path + "AccessModifyingProperties.pptx") as presentation: | |
documentProperties = presentation.document_properties | |
for i in range(documentProperties.count_of_custom_properties): | |
print("Custom Property Name : " + documentProperties.get_custom_property_name(i)) | |
print("Custom Property Value : " + documentProperties.get_custom_property_value[documentProperties.get_custom_property_name(i)]) | |
documentProperties.set_custom_property_value(documentProperties.get_custom_property_name(i), "New Value " + str(i + 1)) | |
presentation.save("CustomDemoModified_out.pptx", slides.export.SaveFormat.PPTX) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
doc = aw.Document(docs_base.my_dir + "Properties.docx") | |
print("1. Document name: 0", doc.original_file_name) | |
print("2. Built-in Properties") | |
for prop in doc.built_in_document_properties : | |
print("0 : 1", prop.name, prop.value) | |
print("3. Custom Properties") | |
for prop in doc.custom_document_properties : | |
print("0 : 1", prop.name, prop.value) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment