How do I embed and extract XMP data associated with a PDF document?

339 views
Skip to first unread message

Support

unread,
Aug 28, 2015, 5:16:09 PM8/28/15
to pdfne...@googlegroups.com
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.

Reply all
Reply to author
Forward
0 new messages