we need to modify XmpMetadata in a pdf document.
The tutorials seems to be old and no longer valid.
For example here:
.../forum/writing-metadata-t7720.html
- Code: Select all
string path = @"C:\Temp\MyDocument.pdf";
var pdfDocument = new Spire.Pdf.PdfDocument(path);
// Why deprecated?
XmpMetadata meta = pdfDocument.DocumentInformation.GetMetaData();
System.Xml.XmlNamespaceManager namespaceManager = meta.NamespaceManager;
System.Xml.XmlDocument doc = meta.XmlData;
namespaceManager.AddNamespace("zf", "myRandomNamespace");
var xmlAttachment = new Spire.Pdf.Attachments.PdfAttachment(Context.XmlPath);
pdfDocument.Attachments.Add(xmlAttachment);
// this is not what I need
pdfDocument.DocumentInformation.SetCustomProperty("test", "ABC123");
// Error: PdfDocument does not contain a definition for 'XmpMetaData'
pdfDocument.XmpMetaData;
// Adding a new namespace "zf" do not save it here
pdfDocument.SaveToFile(path);