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


How do I embed and extract an XMP stream associated with a PDF
I would like to store some custom entries in the XMP stream.

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",
  FilterWriter writer = new FilteWriter(out_file);

// Similarly you can embed or replace an existing XMP stream as
// 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 =
xmp_stm.Put("Subtype", Obj.CreateName("XML")); xmp_stm.Put("Type",
Obj.CreateName("Metadata")); pdfdoc.GetRoot().Put("Metadata",

It is also possible to embed a XMP data from a memory buffer.

Having said this, it is probably a better idea (or at least is much
easier) to store custom key/value pairs using SDF/Cos API (instead as
part of the embedded XMP stream). This is illustrated in SDF sample

You can find more information about SDF/Cos api here: