Search This Blog

Wednesday, November 26, 2014

How to create PDF file through AE using Java Class

The example mentioned below will give basic insights on how to create PDF file through Application Engine using Java classes.
Other way is to use BI Publisher and call the report definition and then publish the report.

To start with, firstly the Appserver/Classes path should contain the JAR file starting with itext.
Write the java code in AE to create PDF file.

Below is the sample code:
/* Create a Document object */
Local JavaObject &Obj_CreateiTextTable = CreateJavaObject("com.lowagie.text.Document");

/* Cretae PDF Writer object */
Local JavaObject &obj_writePDFoutput = GetJavaClass("com.lowagie.text.pdf.PdfWriter").getInstance(&Obj_CreateiTextTable, CreateJavaObject("java.io.FileOutputStream", "/ TESTPDF11262014.pdf", True));
&Obj_CreateiTextTable.open(); /*open the document for writing */
 /* Array with 3 columns */
Local JavaObject &Obj_myPDFTable = CreateJavaObject("com.lowagie.text.pdf.PdfPTable", 3);
 /* Add data to each cell */
&Obj_myPDFTable.addCell("Emp ID");
&Obj_myPDFTable.addCell("Name");
&Obj_myPDFTable.addCell("Address");
&Obj_myPDFTable.addCell("EE1256");
&Obj_myPDFTable.addCell("John");
&Obj_myPDFTable.addCell("Main Street");
 /* Add Table to Document */
&Obj_CreateiTextTable.add(&Obj_myPDFTable);
&Obj_CreateiTextTable.close();  /* close the document */


Output Snapshot:

No comments: