繁体   English   中英

PDF文件无法打开

[英]PDF file not opening

我有Java代码用Java打开pdf文件,它运行得很好。

代码是

    try {
        File pdfFile = new File("/Users/alkandari/Desktop/SMART/Fahim/test.pdf");
        if (pdfFile.exists()) {
            if (Desktop.isDesktopSupported()) {
                Desktop.getDesktop().open(pdfFile);
            } else {
                System.out.println("Awt Desktop is not supported!");
            }
        } else {
            System.out.println("File is not exists!");
        }
        System.out.println("Done");
    } catch (Exception ex) {
        ex.printStackTrace();
    }

但是当我把它放在一些方法中说showMyPDFFile()并尝试在commandLink上调用它时,pdf不会打开。 它说不Awt Desktop is not supported!

 <h:commandLink value="View PDF/ DOC"
 action="#{PersonalInformationDataBean.showMyPDFFile()}" />

知道为什么pdf没有打开?

所以,检查一下,你正在编写一个Web应用程序,对吧?

Desktop类引用本地桌面 - 因此它适用于本地GUI客户端应用程序 即使它得到支持,你也可以在服务器的桌面上打开PDF - 而不是客户端的桌面,我认为这就是你所追求的。

听起来你应该基本上直接链接到PDF文件(作为URL)。 当然,您需要通过Web服务器提供PDF。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM