DEV Community

GroupDocs
GroupDocs

Posted on

How to manipulate your secure PDF, Words, Excel, PowerPoint Documents using C# .NET Metadata API

Metadata is considered “data about data” inside a file and programmers manipulate it to store as well as extract different kinds of important information from a specific document which could relate to it’s various characteristics such as the user permissions. File security is one of the primary concerns for any professional, considering the number of times he may have to use online file transfer services regularly. So, we are constantly on the outlook for software applications as well as APIs which are reliable in terms of the data we could manipulate using them, and the type of files they could let us manage.

Depending upon the business requirements of any organization or even an individual user, one or more types of documents could be processed programmatically for fetching valuable information like the file metadata on .NET platform. Add to it the requirement of working with encrypted or password-protected documents, and the list of applications that could fulfil both these pre-requisites is quite small. GroupDocs.Metadata for .NET API is one such option, which covers both aforementioned requirements and offers much more. Application developers can use it to read, write, analyze and erase metadata from different types of protected documents such as Microsoft Word and PDF files, Excel spreadsheets or PowerPoint presentations.

Additionally, this .NET document metadata API allows you to better utilize memory usage while loading or saving word processing and slides documents within your apps together with the ability to update metadata keys in DOC and DOCX file formats. Learn more –
http://bit.ly/2QESWr1

Following code snippet shows how to work with metadata of a password protected PDF document:

LoadOptions loadOptions = new LoadOptions("password");
using (PdfFormat format = new PdfFormat(Common.MapSourceFilePath(protectedFilePath), loadOptions))
{
// Working with the password-protected document
format.CleanMetadata();
format.Save(Common.MapDestinationFilePath(protectedFilePath));
}

This .NET API supports working with Word formats with less memory consumption. Please note that the DocFormat class implements the IDisposable interface and it's necessary to call the Dispose() method when you're done working with its instance.

Check following code snippets to use less memory while working with Word documents.

using (DocFormat format = new DocFormat(@"d:\input.docx"))
{
// Working with metadata
}

If you are loading a Word document from a stream, it's up to you to close the stream when the file is not needed anymore.

using (Stream stream = File.Open(@"d:\input.doc", FileMode.Open, FileAccess.ReadWrite))
{
using (DocFormat format = new DocFormat(stream))
{
// Working with metadata
}
// The stream is still open here
}

Latest comments (0)