Is it possible to load XMP file in PDF using iText

2019-05-03 22:05发布

问题:

I am having PDF file and XMP file separately by using acrobat I am loading the XMP file in the PDF.

But I want to do this process by automation, so is there is any way to load the XMP file data into PDF file using iTextSharp?

Process I am using in Acrobat to load XMP file.

回答1:

You can set XMP metadata in an existing PDF file using PdfStamper:

PdfReader reader = new PdfReader("in.pdf");
PdfStamper stamper = new PdfStamper(reader, new FileStream("out.pdf", FileMode.Create));
byte[] xmp;
// read xmp file
stamper.XmpMetadata = xmp;
stamper.Close();

I see your screen shot says "Append". Note that the code above overwrites any existing XMP metadata. If that's not what you want, you'd have to get the existing metadata from the PdfReader first, merge the XML with the additional XMP XML and set the merged XMP.

Getting existing XMP metadata:

byte[] xmp = reader.Metadata;