EGL Development User Group

EGL Development User Group

EGL Development User Group

The EGL Development User Group is dedicated to sharing news, knowledge, and insights regarding the EGL language and Business Developer product. Consisting of IBMers, HCL, and users, this community collaborates to advance the EGL ecosystem.

 View Only
Expand all | Collapse all

Print PDF with Apache PDFbox on iSeries

  • 1.  Print PDF with Apache PDFbox on iSeries

    Posted Tue July 21, 2015 08:52 AM

    Hello,

    I am trying to print a PDF directly with the Apache PDFbox API on the iSeries.

     

    This is my Java Code:

    public static void Print_File_(String File) throws IOException, PrinterException {                PrinterJob printJob = PrinterJob.getPrinterJob();                PrintService[] printServices = PrinterJob.lookupPrintServices();        for(PrintService printService : printServices){                System.out.print(printService.getName());            if(printService.getName().contains("Kyo1030_hwcg")){                printJob.setPrintService(printService);                break;            }        }                PDDocument doc = PDDocument                                .load(File);                doc.silentPrint(printJob);                                        }

     

    The function PrinterJob.lookupPrintServices(); throws the following Exception if the application is installed on the WAS 8.5.5 (iSeries)

    In the test environment (Windows) it works....

     

    [21.07.15 13:41:57:338 CEST] 00000094 SystemErr R 21.07.2015 13:41:57.1 EGL1622E:EGL1622E Bei dem Versuch, Funktion PDF_005fPRINT f�r EGL-Service print_pdf_service aufzurufen, ist ein Fehler aufgetreten. EGL0001I Der Fehler ist in print_pdf_service aufgetreten. detail1:500 detail2:FAILED detail3:java.awt.print.PrinterException:No print service found.

     

     

     

    Kind regards,

    Marcel!

     

    Marcel-D


  • 2.  Re: Print PDF with Apache PDFbox on iSeries

    Posted Tue July 21, 2015 09:43 AM

    I've found a solutuion.

     

     

    package custom;import java.awt.print.PrinterException;import java.awt.print.PrinterJob;import java.io.IOException;import javax.print.PrintService;import org.apache.pdfbox.pdmodel.PDDocument;import com.ibm.as400.access.AS400;import com.ibm.as400.javax.print.ISeriesPrintServiceLookup;public class Print_File {        /**         * @param args         */        public static void main(String[] args) {                // TODO Automatisch erstellter Methoden-Stub        }        public static void Print_File_(String File, String Printer)                        throws IOException, PrinterException {                AS400 system1 = new AS400("Power7");                ISeriesPrintServiceLookup ips = new ISeriesPrintServiceLookup(system1);                PrintService[] services = ips.getPrintServices (null,null);                PrinterJob printJob = PrinterJob.getPrinterJob();                                                for (PrintService printService : services) {                        System.out.println(printService.getName());                        if (printService.getName().contains(Printer)) {                                printJob.setPrintService(printService);                                break;                        }                }                PDDocument doc = PDDocument.load(File);                doc.silentPrint(printJob);                doc.close();        }}


     

    Marcel-D