I was able to work on this a little today, and found the issue I was having this weekend. Here's a quick working example. There are instructions at the top of the program.
And here's a CL program that can be called to set up the classpath. You will need to modify this program to change the classpathif you put the iText jar file in a different IFS directory. You will also need to change the library of where the ITEXT1 program is located. (Mine is in a library called ITEXT)
Code:
*********************************************************************** * * Program - ITEXT1 * * Written By - Michael Catalani * 901.672.7572 * * This program will create a PDF document consisting of 5 test pages. * In order to run this example, you must do the following: * * 1. Install the iText Version 5.1.1 Jar from * [URL]http://itextpdf.com/download.php[/URL] (choose the java download) * * 2. Place the iTextPdf-5.1.1.jar file on your IFS * (I placed mine in a path called /java/itext/itextpdf-5.1.1.jar) * * 3. If you have a prior version of iText installed, then * comment out the /define itext511 statement, and uncomment the * /define iText212u statement. Otherwise, if you are installing * iText 5.1.1, then skip this step. * * 4. Change the classpath in the ITEXT1C cl program to the path you * installed the iText jar file, and compile the program. * * 5. Call the ITEXT1C program. * * 6. Change this program (ITEXT1) to a filepath of where you want the * PDF to be created. * (FilePath = Java_NewString( '/ifstest/test.pdf' ); ) * Change this path to a valid path on your IFS. * * 7. Run the ITEXT1 program. * ************************************************************************** h Option( *nodebugio : *SrcStmt ) h DftActGrp( *No ) ActGrp( *New ) h Thread( *Serialize ) ************************************************************************** * iText Version Selector * Uncomment the iTextapi version you are using. * Comment the one(s) you are not using out. ************************************************************************** * /define iText511 */define iText212u ************************************************************************** * iText 5.1.1 Class Name Constants ************************************************************************** * /if defined( iText511 ) d iTextDocumentCLASS... d c 'com.itextpdf.text.Document' d iTextPdfWriterCLASS... d c 'com.itextpdf.text.pdf.PdfWriter' d iTextParagraphCLASS... d c 'com.itextpdf.text.Paragraph' d iTextElementCLASS... d c 'com.itextpdf.text.Element' /endif ************************************************************************** * iText 2.1.1u Class Name Constants ************************************************************************** * /if defined( iText212u ) d iTextDocumentCLASS... d c 'com.lowagie.text.Document' d iTextPdfWriterCLASS... d c 'com.lowagie.text.pdf.PdfWriter' d iTextParagraphCLASS... d c 'com.lowagie.text.Paragraph' d iTextElementCLASS... d c 'com.lowagie.text.Element' /endif ************************************************************************** * Java Class Name Constants ************************************************************************** * d JavaIoStreamCLASS... d c 'java.io.OutputStream' d JavaFileIoStreamCLASS... d c 'java.io.FileOutputStream' d JavaStringCLASS... d c 'java.lang.String' ************************************************************************** * Java Object Descriptions ************************************************************************** * d iTextDocument s o Class( *Java d : iTextDocumentCLASS ) d iTextPdfWriter s o Class( *Java d : iTextPdfWriterCLASS ) d ITextParagraph... d s o Class( *Java d : iTextParagraphCLASS ) d ITextElement... d s o Class( *Java d : iTextElementCLASS ) d jFileOutputStream... d s o Class( *Java d : JavaFileIoStreamCLASS ) d jOutputStream... d s o Class( *Java d : JavaIoStreamCLASS ) ************************************************************************** * Java Constructors ************************************************************************** * d iText_NewDocument... d pr Like( iTextDocument ) d ExtProc( *Java d : iTextDocumentCLASS d : *Constructor ) d iText_NewParagraph... d pr ExtProc( *Java d : iTextParagraphCLASS d : *Constructor ) d Like( iTextParagraph ) d jString Like( jString ) d Java_NewString... d pr Like( jString ) d ExtProc( *Java d : JavaStringCLASS d : *Constructor ) d 65535a Varying Const d Java_NewFileIoStream... d pr Like( jFileOutputStream ) d ExtProc( *Java d : JavaFileIoStreamCLASS d : *Constructor ) d jString Like( jString ) ************************************************************************** * Java Methods ************************************************************************** * d iText_DocumentOpen... d pr ExtProc( *Java d : iTextDocumentCLASS d : 'open') d iText_DocumentClose... d pr ExtProc( *Java d : iTextDocumentCLASS d : 'close' ) d iText_DocumentNewPage... d pr n ExtProc( *Java d : iTextDocumentCLASS d : 'newPage') d iText_DocumentAddParagraph... d pr n ExtProc( *Java d : iTextDocumentCLASS d : 'add' ) d iTextElement Like( iTextElement ) d iText_GetInstance... d pr ExtProc( *Java d : iTextPdfWriterCLASS d : 'getInstance' ) d Static d Like( iTextPdfWriter ) d iTextDocument Like( iTextDocument ) d jOutputStream Like( jOutputStream ) /copy Qsysinc/Qrpglesrc,Jni d Document s Like( iTextDocument ) d Paragraph s Like( iTextParagraph ) d Data s Like( jString ) d FilePath s Like( jString ) d FileIoStream s Like( jFileOutputStream ) d PageNumber s 10i 0 /free //******************************************************** // Warning - no garbage cleanup code has been put in place //******************************************************** // Create the file path stream to the PDF document FilePath = Java_NewString( '/ifstest/test.pdf' ); FileIoStream = Java_NewFileIoStream( FilePath ); // Create a new document instance Document = iText_NewDocument(); iText_GetInstance( Document : FileIoStream ); // Open document iText_DocumentOpen( Document ); // Write out 5 test pages for PageNumber = 1 to 5; iText_DocumentNewPage( Document ); Data = Java_NewString( 'Data For Page - ' + %char( PageNumber )); Paragraph = iText_NewParagraph( Data ); iText_DocumentAddParagraph( Document : Paragraph ); endfor; // Close the document iText_DocumentClose( Document ); return; [SIZE=2][COLOR=#0000aa][SIZE=2][COLOR=#0000aa] [/COLOR][/SIZE][/COLOR][/SIZE]
And here's a CL program that can be called to set up the classpath. You will need to modify this program to change the classpathif you put the iText jar file in a different IFS directory. You will also need to change the library of where the ITEXT1 program is located. (Mine is in a library called ITEXT)
Code:
PGM ADDLIBLE ITEXT *LAST MONMSG CPF2103 ADDENVVAR ENVVAR(CLASSPATH) + VALUE('/JAVA/ITEXT/ITEXTPDF-5.1.1.JAR') + LEVEL(*JOB) + REPLACE(*YES) ADDENVVAR ENVVAR(QIBM_RPG_JAVA_PROPERTIES) + VALUE('-DJAVA.AWT.HEADLESS=TRUE;+ -DOS400.AWT.NATIVE=TRUE;') + REPLACE(*YES) ENDPGM
Comment