The document metadata is a piece of information about the document such as author, editing time, etc. stored inside a document. As a C# developer, you can easily edit the metadata information for PDF documents programmatically on the cloud. In this article, you will learn how to edit the Metadata of PDF files using a REST API in C#.
The following topics shall be covered in this article:
Document Metadata Manipulation REST API and .NET SDK
For editing metadata of a PDF document, I will be using the .NET SDK of GroupDocs.Metadata Cloud API. It allows you to add, edit, retrieve and remove metadata from almost all industry-standard file formats. You can perform such operations on PDF, Microsoft Word, Excel spreadsheets, PowerPoint presentations, Outlook emails, Visio, OneNote, Project, audio, video, AutoCAD, archive, JPEG, BMP, PNG, and TIFF. It also provides Java SDK as its document metadata manipulation family members for the Cloud API.
You can install GroupDocs.Metadata Cloud SDK for .NET to your Visual Studio project from the NuGet Package manager as shown below:
You may also install the NuGet Package using the following command in the Package Manager console:
Please get your Client ID and Client Secret from the dashboard before you start following the steps and available code examples. Once you have your client ID and Secret, add in the code as shown below:
Edit Metadata of PDF Files using REST API in C#
You can set metadata of PDF documents by following the simple steps given below:
- Upload the PDF file to the Cloud
- Update Metadata of PDF Documents using C#
- Download the resultant file
Upload the Document
Firstly, upload the PDF file to the Cloud using the code sample given below:
As a result, the uploaded PDF file (input.pdf) will be available in the files section of your dashboard on the cloud.
Update Metadata of PDF Files using C#
You can update the metadata of a PDF file programmatically by following the steps given below.
- Create an instance of MetadataApi
- Set the PDF file path in the FileInfo model
- Define SetOptions
- Provide NewValue and Type for SetProperty
- Define SearchCriteria, provide NameOptions for which to update the value
- Create SetRequest with SetOptions
- Get results by calling the MetadataApi.Set() method
The following code sample shows how to set the metadata by property name of a PDF document using a REST API.
The following code snippet shows how to match the exact property name by setting the ExactPhrase property to True:
The following code snippet shows how to define search criteria using Regular expressions to provide the MatchOptions:
The following code snippet shows how to update the metadata by providing the property value:
Download the Updated File
The above code samples will save the updated PDF file on the cloud and can be downloaded using the following code sample:
Please try the following free online PDF Metadata manipulation tool, which is developed using the above API.
In this article, you have learned how to edit the Metadata of PDF documents on the cloud. This article also explained how to programmatically upload a PDF file on the cloud and then download the updated file from the cloud. You can learn even more about GroupDocs.Metadata Manipulation Cloud API using the documentation. We also provide an API Reference section that lets you visualize and interact with our APIs directly through the browser. In case of any ambiguity, please feel free to contact us on the forum.