0
我在項目位置如何打開PDF文件PDF如何使用vaadin代碼在項目文件夾中打開pdf文件?
我的項目名稱爲MyProject的
我的PDF是項目文件夾
MyProject的\ PDF閱讀器\如何檢驗.pdf打開我的PDF文件下
我需要在項目的位置來打開PDF文件
我曾嘗試下面的代碼
final Button viewBtn= new Button("View Policy Schedule");
viewBtn.addClickListener(newButton.ClickListener() public void buttonClick(ClickEvent event) {
Window window = new Window();
window.setResizable(true);
window.setCaption("Claim Form Covering Letter PDF");
window.setWidth("800");
window.setHeight("600");
window.setModal(true);
window.center();
final String filepath = "Pdf//test.pdf";
File f = new File(filepath);
System.out.println(f.getAbsolutePath());
Path p = Paths.get(filepath);
String fileName = p.getFileName().toString();
StreamResource.StreamSource s = new StreamResource.StreamSource() {
/**
*
*/
private static final long serialVersionUID = 9138325634649289303L;
public InputStream getStream() {
try {
File f = new File(".");
System.out.println(f.getCanonicalPath());
FileInputStream fis = new FileInputStream(f);
return fis;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
};
StreamResource r = new StreamResource(s, fileName);
Embedded e = new Embedded();
e.setSizeFull();
e.setType(Embedded.TYPE_BROWSER);
r.setMIMEType("application/pdf");
e.setSource(r);
window.setContent(e);
UI.getCurrent().addWindow(window);
}
});
這不工作我有一個文件沒有發現異常