icepdf无法在JFrame中的linux实例上呈现

问题描述 投票:0回答:1

我在我的网络项目中使用icepdf。当我在eclipse中运行这个项目时它运行正常,并且当我在tomcat版本8/9上使用这个项目时运行它。但是当我在Linux实例中部署这场战争时,一切都很好,但pdf不会在JFrame中呈现。我的java版本和tomcat版本也和我本地使用的相同。

这是我的代码

import org.icepdf.ri.common.SwingController;
import org.icepdf.ri.common.SwingViewBuilder;
import java.io.InputStream;
import javax.swing.*; 
public class PdfPreview {
public static void pdfPreview(InputStream stream) {

    // 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.DISPOSE_ON_CLOSE);
    applicationFrame.getContentPane().add(viewerComponentPanel);

    // Now that the GUI is all in place, we can try openning a PDF
    controller.openDocument(stream, "Pdf Viewer", null);
    // show the component
    applicationFrame.pack();
    applicationFrame.setVisible(true);
}}

stream来自这里

java swing icepdf
1个回答
1
投票

基于Swing的查看器旨在作为胖客户端作为独立应用程序运行。您的代码可能在服务器上正常运行,但GUI将加载到服务器系统而不是您的系统上。当服务器尝试加载Swing子系统时,可能还会出现无头异常。

如果要通过Web服务器启动Viewer应用程序,则需要构建和部署Java WebStart应用程序(JWS)。这里有一个例子,http://anonsvn.icesoft.org/repo/icepdf/tags/icepdf-6.3.0/icepdf/examples/jws/。关于签署罐子,您需要进行一些自己的研究。

您还可以使用ICEpdf库将PDF文档的页面另存为图像,然后可以使用Tomcat将图像提供给请求客户端。有一些示例代码使用JSF / ICEfaces http://anonsvn.icesoft.org/repo/icepdf/tags/icepdf-6.3.0/icepdf/examples/icefaces/。核心捕获由这个Servlet类http://anonsvn.icesoft.org/repo/icepdf/tags/icepdf-6.3.0/icepdf/examples/icefaces/src/main/java/org/icepdf/examples/jsf/viewer/servlet/PdfRenderer.java完成

© www.soinside.com 2019 - 2024. All rights reserved.