Q: I am impressed with the product so far. However, I can’t find any
mention of XMP (XML Metadata incorporated in a pdf file) in the
documentation or the samples. Does your product support the creation
of an XMP section and the insertion of custom XMP style metadata?
------
A: You can extract this XMP stream as follows :
...
Obj xmp_stm = pdfdoc.GetRoot().FindObj("Metadata");
if (xmp_stm != null) {
// extract embedded XMP ...
Obj stm = xmp_stm.GetDecodedStream();
FilterReader reader = new FilterReader(stm);
StdFile out_file = new StdFile("myxmp.xml",
StdFile.OpenMode.e_write_mode);
FilterWriter writer = new FilteWriter(out_file);
writer.WriteFilter(reader);
writer.Flush();
out_file.Close();
}
// Similarly you can embed or replace an existing XMP stream as
follows:
// Using C# - Add XMP metadata to document catalog.
...
StdFile xmp_file = new StdFile("myxmp.xml",
StdFile.OpenMode.e_read_mode);
FilterReader reader = new FilterReader(xmp_file);
Obj xmp_stm = pdfdoc.CreateIndirectStream(reader);
xmp_stm.PutName("Subtype", "XML");
xmp_stm.PutName("Type", "Metadata");
pdfdoc.GetRoot().Put("Metadata", xmp_stm);
xmp_file.Close()
It is also possible to read or embed a XMP data from a memory buffer.