How to retrieve custom metadata from exisisting PDF document?
The custom metadata value added to a WinForms PDF document can be retrieved from XmpMetadata of DocumentInformation found in PdfLoadedDocument with the Custom metadata key which is given during addition of custom metadata to a PDF document:
Please find the code snippet for adding custom metadata to a PDF document with key and value:
C#:
//Create custom schema with namespace. CustomSchema customSchema = new CustomSchema(metaData, "custom", "http://www.syncfusion.com"); customSchema["CutomKey1"] = "CustomValue1"; customSchema["CutomKey2"] = "CustomValue2"; customSchema["CutomKey3"] = "CustomValue3";
Please find the code snippet for accessing the custom metadata value from existing PDF document with the help of custom metadata key and namespace:
C#:
//Load the PDF document PdfLoadedDocument ldoc = new PdfLoadedDocument("CustomMetaField.pdf"); //Get the XmlDocument from XMP metadata XmlDocument xmlDoc = ldoc.DocumentInformation.XmpMetadata.XmlData; //Get the XmlElement from XmlDocument XmlElement xmlElements = xmlDoc.DocumentElement; // Getting the custom metadata value with the help of custom metadata key string customValue1 = GetCustomData(xmlElements, "CutomKey1"); string customValue2 = GetCustomData(xmlElements, "CutomKey2"); string customValue3 = GetCustomData(xmlElements, "CutomKey3"); //Close the document ldoc.Close(true); private static string GetCustomData(XmlElement xmlElem, string customMetaKey) { string customValue = ""; string tagName = "custom:" + customMetaKey; // get the custom meta data value with tag name and namespace XmlNodeList nodeList = xmlElem.GetElementsByTagName(tagName); if(nodeList.Count>0) customValue = (nodeList[0].InnerXml); return customValue; }
The sample for retrieving the custom metadata from PDF loaded document can be downloaded from the link mentioned below:
https://www.syncfusion.com/downloads/support/directtrac/general/ze/RetrieveCustomMeta673441964
I hope you enjoyed learning about how to retrieve custom metadata from exisisting PDF document.
You can refer to our WinForms PDF’s feature tour page to know about its other groundbreaking feature representations. You can also explore our WinForms PDF documentation to understand how to present and manipulate data.
For current customers, you can check out our WinForms components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our WinForms PDF and other WinForms components.
If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!