PeopleSoft Add XMP Metadata PDF Example Tutorial

In this tutorial, we will discuss how to embed an XMP Metadata Stream into a PDF document using PeopleCode. We have been discussing for a while on creating Metadata in PDF documents using PeopleCode. This example can be considered as an extension of the examples, as it dwells more on adding this metadata as an XMP (Extensible Metadata Platform) stream through PeopleSoft. For you to understand more on XMP stream, you can refer to the Java equivalent tutorial which we published some time before.Also, to add this XMP stream into PDF you need to know how to add basic metadata information to a PDF through PeopleCode. For this, you can refer to the beginner tutorial on PDF Metadata. This tutorial is built on top of that one and getting a good understanding on the beginner tutorial is recommended.

We begin with creating a Document and PdfWriter object. We also put some contents inside the new PDF file as per the tutorials earlier. The PeopleCode is provided below;
Local JavaObject &Obj_PDF_XMP_Metadata = CreateJavaObject("com.lowagie.text.Document");
Local JavaObject &obj_writeXMPStream_l = GetJavaClass("com.lowagie.text.pdf.PdfWriter").getInstance(&Obj_PDF_XMP_Metadata, CreateJavaObject("java.io.FileOutputStream", "XMP_Metadata_Example.pdf", True));
&Obj_PDF_XMP_Metadata.open();
&Obj_PDF_XMP_Metadata.add(CreateJavaObject("com.lowagie.text.Paragraph", "Add XMP Metadata Information to PDF File"));
We know add the metadata information using the Document object in traditional way. (i.e. using the info dictionary).We add Title, Author, Subject, Keywords, Creator and Creation data information.
&Obj_PDF_XMP_Metadata.addTitle("Insert XMP Metadata to PDF Example Tutorial");
&Obj_PDF_XMP_Metadata.addAuthor("PeopleSoft Tutorials");
&Obj_PDF_XMP_Metadata.addSubject(" XMP Metadata Addition to PDF - PeopleSoft Example");
&Obj_PDF_XMP_Metadata.addKeywords("PDF XMP Metadata, iText, PeopleSoft, PDF");
&Obj_PDF_XMP_Metadata.addCreator("Test");
&Obj_PDF_XMP_Metadata.addCreationDate();
Finally, we use the "createXmpMetadata" method of the PdfWriter class, to automatically convert this information into an XMP stream. This step will make sure that metadata gets embedded into the PDF file as an XMP (XML) stream and can be read by non-pdf aware applications. The Peoplecode is provided below;
&obj_writeXMPStream_l.createXmpMetadata();
&Obj_PDF_XMP_Metadata.close();
The complete PeopleCode example to embed XMP metadata stream to a PDF document using PeopleCode is provided below;
Local JavaObject &Obj_PDF_XMP_Metadata = CreateJavaObject("com.lowagie.text.Document");
Local JavaObject &obj_writeXMPStream_l = GetJavaClass("com.lowagie.text.pdf.PdfWriter").getInstance(&Obj_PDF_XMP_Metadata, CreateJavaObject("java.io.FileOutputStream", "XMP_Metadata_Example.pdf", True));
&Obj_PDF_XMP_Metadata.open();
&Obj_PDF_XMP_Metadata.add(CreateJavaObject("com.lowagie.text.Paragraph", "Add XMP Metadata Information to PDF File"));
&Obj_PDF_XMP_Metadata.addTitle("Insert XMP Metadata to PDF Example Tutorial");
&Obj_PDF_XMP_Metadata.addAuthor("PeopleSoft Tutorials");
&Obj_PDF_XMP_Metadata.addSubject(" XMP Metadata Addition to PDF - PeopleSoft Example");
&Obj_PDF_XMP_Metadata.addKeywords("PDF XMP Metadata, iText, PeopleSoft, PDF");
&Obj_PDF_XMP_Metadata.addCreator("Test");
&Obj_PDF_XMP_Metadata.addCreationDate();
&obj_writeXMPStream_l.createXmpMetadata();
&Obj_PDF_XMP_Metadata.close();
How do we read back this information to confirm that we have used XMP Metadata stream for the PDF? In this next tutorial, we will discuss how to read this XML Metadata information from a PDF file using PeopleCode

No comments:

Post a Comment