1 Reply Latest reply: Jul 23, 2013 9:53 AM by user6481339 RSS

    Java Web Start PrinterJob not working

    e9a73435-d60e-4dd6-98ac-5b2bf5eb9283

      I have a JavaFX application that uses a AWT PrinterJob to print the contents of a table. Everything is working fine while on development and when I run the application locally but when I sing it and distribute it via Web start, the print dialog box doesn't open and the application crashes.

      From my research I found that I could use the PrintServices of the JNLP API but I also saw that from Java 5.0 onwards you don't have too. I tried it anyway but I get worst results as I can't make it run even locally. I know for a fact that it could work because I do the same thing for another Java application I discribute using Web Start and have no problems there. The difference in this application is that it is a JavaFX application and the working one is a Swing one if that gives you any clues.

      Below is the function I use to create the PrinterJob and print my Printable class

      @FXML

          public void printToImage() {

              for (CompactResult cr : getResDataList()) {

                  getPrintDataList().add(cr);

              }

              CompactResultPrinter p = new CompactResultPrinter(getPrintDataList(), getResourceBoundle(),

                      getFrom(), getTo(), getFinalSearchList());

              /**

               * Code below works on development

               */

              PrinterJob job = PrinterJob.getPrinterJob();

              PageFormat pf = job.defaultPage();

              pf.setOrientation(PageFormat.PORTRAIT);

              Paper paper = new Paper();

              paper.setImageableArea(0, 0, paper.getWidth(), paper.getHeight());

              pf.setPaper(paper);

              job.setPrintable(p, pf);

              boolean ok = job.printDialog();

              if (ok) {

                  try {

                      job.print();

                  } catch (PrinterException ex) {

                      ex.printStackTrace();

                  }

              }

              closeMedAdvancedSearchStage();

          }

       

      Below I include the output I get in Java Console.

      Caused by: java.lang.NullPointerException

      at javax.print.PrintServiceLookup.getServicesForContext(Unknown Source)

      at javax.print.PrintServiceLookup.getListOfLookupServices(Unknown Source)

      at javax.print.PrintServiceLookup.getAllLookupServices(Unknown Source)

      at javax.print.PrintServiceLookup.lookupDefaultPrintService(Unknown Source)

      at sun.print.Win32PrintServiceLookup.getWin32PrintLUS(Unknown Source)

      at sun.awt.windows.WPrinterJob.getPrintService(Unknown Source)

      at sun.print.RasterPrinterJob.setPrintable(Unknown Source)

      at AdvancedSearchDetailedResultsTableViewController.printToImage(AdvancedSearchDetai..

       

      Any clues?

       

      Thanks