PeopleSoft Add PDF Metadata Example Tutorial

In this tutorial, we will explain how to create a PDF file in PeopleSoft and add metadata information to the PDF file, using the Java iText library. We have been discussing for a while on metadata addition / update through Java and we will be extending this to PeopleCode in the upcoming tutorials. It would be wise to go through the beginner tutorial on creating PDF documents in PeopleSoft as it would serve as a good reference to this tutorial. For adding metadata information into a PDF document through PeopleCode, we will begin with a Document and PdfWriter objects, and utilize some methods present in the Document (com.lowagie.text.Document) class to stamp the metadata information as an info dictionary. We will not be using XMP stream for adding metadata in this tutorial; I will try and cover this later. The step by step guide is provided below;

To add metadata into PDF using PeopleCode, begin by creating a Document object and a PdfWriter object. I will be adding some dummy contents into the PDF file after opening the Document object. The PeopleCode snippet is provided below;
/* Create a document object */
Local JavaObject &Obj_PDF_Metadata_Addition = CreateJavaObject("com.lowagie.text.Document");
/* Get an instance of PDF Writer */
Local JavaObject &obj_writePDFoutput_l = GetJavaClass("com.lowagie.text.pdf.PdfWriter").getInstance(&Obj_PDF_Metadata_Addition, CreateJavaObject("java.io.FileOutputStream", "Hello.pdf", True));
/* add some contents into the PDF */
&Obj_PDF_Metadata_Addition.open();
&Obj_PDF_Metadata_Addition.add(CreateJavaObject("com.lowagie.text.Paragraph", "Add Metadata Information to PDF File from PeopleSoft"));
Now, to add Title information as metadata to the PDF we use the "addTitle" method. To add author information, we use "addAuthor" method. To add subject information into the metadata, we use "addSubject" method and to add Keyword information into the PDF will use "addKeywords" method. All these methods are a part of the Document object. We also use "addCreator" method to add the creator information inside the PDF. Finally, we add the creation date as timestamp to the PDF by invoking the "addCreationDate" method. The PeopleCode snippet that explains how to add these information as metadata to the PDF file is provided below;
&Obj_PDF_Metadata_Addition.addTitle("Add Metadata to PDF Example Tutorial");
&Obj_PDF_Metadata_Addition.addAuthor("PeopleSoft Tutorials");
&Obj_PDF_Metadata_Addition.addSubject("Metadata Addition to PDF - PeopleSoft Example");
&Obj_PDF_Metadata_Addition.addKeywords("Metadata, iText, PeopleSoft, PDF");
&Obj_PDF_Metadata_Addition.addCreator("Test");
&Obj_PDF_Metadata_Addition.addCreationDate();
&Obj_PDF_Metadata_Addition.close();
The complete PeopleCode example to add metadata information to a PDF file is provided below;
Local JavaObject &Obj_PDF_Metadata_Addition = CreateJavaObject("com.lowagie.text.Document");
Local JavaObject &obj_writePDFoutput_l = GetJavaClass("com.lowagie.text.pdf.PdfWriter").getInstance(&Obj_PDF_Metadata_Addition, CreateJavaObject("java.io.FileOutputStream", "Hello.pdf", True));
&Obj_PDF_Metadata_Addition.open();
&Obj_PDF_Metadata_Addition.add(CreateJavaObject("com.lowagie.text.Paragraph", "Add Metadata Information to PDF File from PeopleSoft"));
&Obj_PDF_Metadata_Addition.addTitle("Add Metadata to PDF Example Tutorial");
&Obj_PDF_Metadata_Addition.addAuthor("PeopleSoft Tutorials");
&Obj_PDF_Metadata_Addition.addSubject("Metadata Addition to PDF - PeopleSoft Example");
&Obj_PDF_Metadata_Addition.addKeywords("Metadata, iText, PeopleSoft, PDF");
&Obj_PDF_Metadata_Addition.addCreator("Test");
&Obj_PDF_Metadata_Addition.addCreationDate();
&Obj_PDF_Metadata_Addition.close();
When you run this example at the application server (field change etc) or process scheduler, you will find the PDF file sitting on your server with metadata information added as we have provided.

No comments:

Post a Comment