javaitextibm-midrangeibm-ifs

a very simple case does not write pdf file by using itext in IBM i


i'm trying to use itext (5.5.13) in IBM i (AKA iseries, Power, long ago AS/400). It could be done embedding java code into RPG ILE procedures, or executing plain java. We use Apache POI for Excel for a while, and it works well. We are testing itext now, but some issue persist yet. Given that, I'm trying to test itext in plain java into IBM i. I prepared a very simple example, taken from listing 1.1 of "Itext in action", and run it. It seems to work well, but nothing is generated. No pdf file results. And no error appears while running. am i forgetting something? are there some other aspects to take in account? here is the code:

package QOpenSys.CONSUM.Testjeu;

import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

public class test1{
    public static final String filePdf = "/QOpenSys/MyFolder/Testjeu/PdfRead1.pdf";
    
    public static void main(String[] args)
    throws DocumentException, IOException
     { 
        ///QOpenSys/MyFolder/Test/WrkBookRead1.pdf

        //pdfDocument = new_DocumentVoid()
        Document pdfDocument = new Document();

        //pdfWriter = get_PdfWriter( pdfDocument: pdfFilePath);
        PdfWriter.getInstance(pdfDocument, new FileOutputStream( filePdf ));

        // jItxDocumentOpen( pdfDocument );
        pdfDocument.open();

        //pdfParagraph = new_PdfParagraphStr( PhraseString );
        Paragraph jItxParagraph = new Paragraph("Hola, pdf");

        //addToDocPg = jItxDocumentAddParagraph( pdfDocument: pdfParagraph );
        pdfDocument.add(jItxParagraph);

        //jItxDocumentClose( pdfDocument );
        pdfDocument.close();
    }
}

Solution

  • Solved. As said before, there was a first issue: it seems java function ran well because not errors/warnings were visible at qshell. It was false: errors were sent to outq, and were available at spool file. Being reviewed, it was a simple classpath issue. It required a full day to figure out what failed locating classpath. Now it works, and pdf is created. I ran it on qshell, declaring environment variables for java_home (three jvm are executed concurrently by several applications), for classpath, and a couple required for tracing. Classpath declares first my class and secondly itext classes. Remaining classes comes from JRE. I have a full list of classes loaded by class loader. I hope it will help to find what fails in our embedded RPG ILE call to itext.