I am using ICEPDF to show and print a PDF doc within my Java Application.
I get the following exception:
org.icepdf.core.pobjects.Catalog <clinit>
INFO: ICEsoft ICEpdf Core 4.1.4
Exception in thread "Thread-4" java.lang.ArrayIndexOutOfBoundsException: 0
at org.icepdf.ri.common.PrintHelper.getSetupDialog(PrintHelper.java:526)
at org.icepdf.ri.common.PrintHelper.setupPrintService(PrintHelper.java:199)
at org.icepdf.ri.common.SwingController.initialisePrinting(SwingController.java:2590)
at org.icepdf.ri.common.SwingController.access$400(SwingController.java:102)
at org.icepdf.ri.common.SwingController$3.run(SwingController.java:2548)
at java.lang.Thread.run(Thread.java:680)
The code I am using is:
public class ViewerComponentExample {
public static void main(String[] args) {
// Get a file from the command line to open
String filePath = "boll.pdf";
// build a component controller
SwingController controller = new SwingController();
SwingViewBuilder factory = new SwingViewBuilder(controller);
JPanel viewerComponentPanel = factory.buildViewerPanel();
// add interactive mouse link annotation support via callback
controller.getDocumentViewController().setAnnotationCallback(
new org.icepdf.ri.common.MyAnnotationCallback(
controller.getDocumentViewController()));
JFrame applicationFrame = new JFrame();
applicationFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
applicationFrame.getContentPane().add(viewerComponentPanel);
// Now that the GUI is all in place, we can try openning a PDF
controller.openDocument(filePath);
// show the component
applicationFrame.pack();
applicationFrame.setVisible(true);
}
}
The above shows the viewer fine and it allows all operations apart from printing! (see exception above).
Any help is highly appreciated.
Thanks
Unfortunatly, this exception appears when no printer is available on you OS. Here is the icepdf source code:
"services" is defined like this:
If no services match, the "services" array is zero-length: http://docs.oracle.com/javase/6/docs/api/javax/print/PrintServiceLookup.html#lookupPrintServices(javax.print.DocFlavor, javax.print.attribute.AttributeSet)
Maybe a solution would be to create a "/dev/null" printer. I don't know how if this is easy to do...