我想在现有的Java(SWT)-Application中打开PDF文件。 PDF不应在外部框架中打开。我尝试通过OLE接口但没有成功。
clientSite = new OleControlSite(frame, SWT.NONE, "AcroExch.App", fileName);
automation = new OleAutomation(clientSite);
clientSite.doVerb(OLE.OLEIVERB_OPEN);
答案 0 :(得分:1)
你可以试试这个
try {
File pdfFile = new File("c:\\stack-overflow.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();
}
//如果您想使用adobe打开pdf,请按照下面的说明
try{
if ((new File("c:\\your_file.pdf")).exists()) {
Process p = Runtime
.getRuntime()
.exec("rundll32 url.dll,FileProtocolHandler c:\\your_file.pdf");
p.waitFor();
} else {
System.out.println("File does not exist");
}
} catch (Exception ex) {
ex.printStackTrace();
}