Use Dictionary<string, string> like so:
static string GetPropertyByName(string filePath, string propertyName)
{
if (String.IsNullOrEmpty(filePath) || !System.IO.File.Exists(filePath) || String.IsNullOrEmpty(propertyName)) { return null; }
Dictionary<string, string> propertyInfo = GetPdfProperties(filePath);
foreach (KeyValuePair<string, string> property in propertyInfo)
{
if (property.Key == propertyName) { return property.Value; }
}
return null; ;
}
static Dictionary<string, string> GetPdfProperties(string filePath)
{
Dictionary<string, string> propertyInfo = null;
using (PdfReader reader = new PdfReader(filePath))
{
propertyInfo = reader.Info;
reader.Close();
}
return propertyInfo;
}
Now just look for the property you want by name (Key), like so:
string pdfFilePath = @"C:\....\Some File.pdf";
string propertyName = "CustomProperty1";
string propertyValue = GetPropertyByName(pdfFilePath, propertyName)
if (propertyValue == null) { Console.WriteLine("Property "+ propertyName + " was not found."); }
else { Console.WriteLine(propertyName + " = " + propertyValue); }
Note: Above code has been tested.