ICEPDF打印问题

发布于 2024-10-19 22:46:53 字数 1914 浏览 0 评论 0原文

我正在使用 ICEPDF 在我的 Java 应用程序中显示和打印 PDF 文档。

我得到以下异常:

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)

我使用的代码是:

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);
    }
}

上面显示查看器很好,它允许除打印之外的所有操作! (参见上面的例外)。

非常感谢任何帮助。

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

じее 2024-10-26 22:46:53

不幸的是,当您的操作系统上没有可用的打印机时,会出现此异常。
这是icepdf源代码:

return ServiceUI.printDialog(graphicsConfiguration,
    point.x,
    point.y,
    services, services[0],
    DocFlavor.SERVICE_FORMATTED.PRINTABLE,
    printRequestAttributeSet);

“services”的定义如下:

private PrintService[] lookForPrintServices() {
    PrintService[] services = PrintServiceLookup.lookupPrintServices(
        DocFlavor.SERVICE_FORMATTED.PRINTABLE, null);
    PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
    if (defaultService != null && services.length > 1) {
        PrintService printService;
        for (int i = 1, max = services.length; i < max; i++) {
            printService = services[i];
            if (printService.equals(defaultService)) {
                PrintService tmp = services[0];
                services[0] = defaultService;
                services[i] = tmp;
                break;
            }
        }
    }
    return services;
}

如果没有服务匹配,则“services”数组的长度为零:
http://docs .oracle.com/javase/6/docs/api/javax/print/PrintServiceLookup.html#lookupPrintServices(javax.print.DocFlavor, javax.print.attribute.AttributeSet)

也许解决方案是创建一个“ /dev/null”打印机。我不知道这是否容易做到......

Unfortunatly, this exception appears when no printer is available on you OS.
Here is the icepdf source code:

return ServiceUI.printDialog(graphicsConfiguration,
    point.x,
    point.y,
    services, services[0],
    DocFlavor.SERVICE_FORMATTED.PRINTABLE,
    printRequestAttributeSet);

"services" is defined like this:

private PrintService[] lookForPrintServices() {
    PrintService[] services = PrintServiceLookup.lookupPrintServices(
        DocFlavor.SERVICE_FORMATTED.PRINTABLE, null);
    PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
    if (defaultService != null && services.length > 1) {
        PrintService printService;
        for (int i = 1, max = services.length; i < max; i++) {
            printService = services[i];
            if (printService.equals(defaultService)) {
                PrintService tmp = services[0];
                services[0] = defaultService;
                services[i] = tmp;
                break;
            }
        }
    }
    return services;
}

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...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文