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 PDF metadata in C# programmatically. In this article, you will learn how to build a PDF metadata editor in a .NET application.
The following topics shall be covered in this article:
PDF Metadata Editor - API Installation

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:

Install GroupDocs.Metadata Cloud via NuGet Package Manager
You may also install the NuGet Package using the following command in the Package Manager console:
Install-Package GroupDocs.Metadata-Cloud
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:
string clientID = "112f0f38-9dae-42d5-b4fc-cc84ae644972"; | |
string clientSecret = "16ad3fe0bdc39c910f57d2fd48a5d618"; | |
string myStorage = ""; | |
Configuration configuration = new Configuration(clientID, clientSecret); | |
configuration.ApiBaseUrl = "https://api.groupdocs.cloud"; |
Edit PDF Metadata in C# Programmatically
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:
# api initialization | |
FileApi fileApi = new FileApi(configuration); | |
string path = @"C:\Files"; | |
var file = Directory.GetFiles(path, "input.pdf", SearchOption.AllDirectories).FirstOrDefault(); | |
if (file.Length != 0) | |
{ | |
var relativeFilePath = file.Replace(path, string.Empty).Trim(Path.DirectorySeparatorChar); | |
var fileStream = File.Open(file, FileMode.Open); | |
fileApi.UploadFile(new UploadFileRequest(relativeFilePath, fileStream, myStorage)); | |
fileStream.Close(); | |
} |
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 edit PDF metadata 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 SetPropert
- 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.
# api initialization | |
var apiInstance = new MetadataApi(configuration); | |
try | |
{ | |
var fileInfo = new GroupDocs.Metadata.Cloud.Sdk.Model.FileInfo | |
{ | |
FilePath = "input.pdf", | |
StorageName = myStorage | |
}; | |
// Define Set Options | |
var options = new SetOptions | |
{ | |
FileInfo = fileInfo, | |
Properties = new List<SetProperty> | |
{ | |
new SetProperty | |
{ | |
NewValue = "hello", | |
Type = "String", | |
SearchCriteria = new SearchCriteria | |
{ | |
NameOptions = new NameOptions | |
{ | |
Value = "Keywords" | |
} | |
}, | |
} | |
} | |
}; | |
// Define Set Request | |
var request = new SetRequest(options); | |
var response = apiInstance.Set(request); | |
Console.WriteLine($"Count of changes: {response.SetCount}"); | |
Console.WriteLine("Resultant file path: " + response.Path); | |
} | |
catch (Exception e) | |
{ | |
Console.WriteLine("Exception while calling MetadataApi: " + e.Message); | |
} |

Set Metadata by Property Name
The following code snippet shows how to match the exact property name by setting the ExactPhrase property to True:
# api initialization | |
var apiInstance = new MetadataApi(configuration); | |
var fileInfo = new GroupDocs.Metadata.Cloud.Sdk.Model.FileInfo | |
{ | |
FilePath = "input.pdf", | |
StorageName = myStorage | |
}; | |
// Define Set Options | |
var options = new SetOptions | |
{ | |
FileInfo = fileInfo, | |
Properties = new List<SetProperty> | |
{ | |
new SetProperty | |
{ | |
NewValue = "This is title", | |
Type = "String", | |
SearchCriteria = new SearchCriteria | |
{ | |
NameOptions = new NameOptions | |
{ | |
Value = "Title", | |
MatchOptions = new MatchOptions | |
{ | |
ExactPhrase = true | |
} | |
} | |
}, | |
} | |
} | |
}; | |
// Define Set Request | |
var request = new SetRequest(options); | |
var response = apiInstance.Set(request); |

Set Metadata by Matching Exact Property Name
The following code snippet shows how to define search criteria using Regular expressions to provide the MatchOptions:
# api initialization | |
var apiInstance = new MetadataApi(configuration); | |
var fileInfo = new GroupDocs.Metadata.Cloud.Sdk.Model.FileInfo | |
{ | |
FilePath = "input.pdf", | |
StorageName = myStorage | |
}; | |
// Define Set Options | |
var options = new SetOptions | |
{ | |
FileInfo = fileInfo, | |
Properties = new List<SetProperty> | |
{ | |
new SetProperty | |
{ | |
NewValue = "new value", | |
Type = "String", | |
SearchCriteria = new SearchCriteria | |
{ | |
NameOptions = new NameOptions | |
{ | |
Value = "^Tit.*", | |
MatchOptions = new MatchOptions | |
{ | |
IsRegex = true | |
} | |
} | |
}, | |
} | |
} | |
}; | |
// Define Set Request | |
var request = new SetRequest(options); | |
var response = apiInstance.Set(request); |

Set Metadata by Matching Property Name with Regular Expression
The following code snippet shows how to update the metadata by providing the property value:
# api initialization | |
var apiInstance = new MetadataApi(configuration); | |
var fileInfo = new GroupDocs.Metadata.Cloud.Sdk.Model.FileInfo | |
{ | |
FilePath = "input.pdf", | |
StorageName = myStorage | |
}; | |
// Define Set Options | |
var options = new SetOptions | |
{ | |
FileInfo = fileInfo, | |
Properties = new List<SetProperty> | |
{ | |
new SetProperty | |
{ | |
NewValue = "Simply set by Property Value", | |
Type = "String", | |
SearchCriteria = new SearchCriteria | |
{ | |
ValueOptions = new ValueOptions | |
{ | |
Value = "Windows User", | |
Type = "String" | |
} | |
}, | |
} | |
} | |
}; | |
// Define Set Request | |
var request = new SetRequest(options); | |
var response = apiInstance.Set(request); |

Set Metadata by Matching 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:
# api initialization | |
var fileApi = new FileApi(configuration); | |
var file = "metadata\\set_metadata\\input_pdf\\input.pdf"; | |
var downloadRequest = new DownloadFileRequest(file, myStorage); | |
Stream downloadResponse = fileApi.DownloadFile(downloadRequest); | |
using (var fileStream = File.Create("C:\\Files\\sample_input.pdf")) | |
{ | |
downloadResponse.Seek(0, SeekOrigin.Begin); | |
downloadResponse.CopyTo(fileStream); | |
} |
Online Metadata Editor
Please try the following free free Metadata editor, which is developed using the above API.
https://products.groupdocs.app/metadata/pdf
Conclusion
In this article, you have learned how to edit PDF metadata in C#. 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 built your own PDF metadata editor using GroupDocs.Metadata Manipulation Cloud API. Please visit the documentation to learn further. 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.