StreamSource s = new StreamResource.StreamSource() {
@Override
public InputStream getStream() {
try {
/*HttpSession session = (HttpSession) VaadinSession.getCurrent().getSession();*/
//String basePath = session.getServletContext().getRealPath("/");
/*File f = new File("E:/CN-book-of-vaadin-zh.pdf");*/
String basepath = VaadinService.getCurrent()
.getBaseDirectory().getAbsolutePath();
File file = new File(basepath,"files/member_user_book_2.1.pdf");
System.out.println(basepath+"sadfffffffffffffffffffffffffffffffffffffffffff");
FileInputStream fis = new FileInputStream(file);
return fis;
}
catch (Exception e) {
e.printStackTrace();
return null;
}
}
};
StreamResource r = new StreamResource(s, "member_user_book_2.1.pdf");
Embedded e = new Embedded();
e.setSizeFull();
e.setType(Embedded.TYPE_BROWSER);
r.setMIMEType("application/pdf");
e.setSource(r);
this.setSizeFull();
this.addComponent(e);
Vaadin——打開PDF文檔
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.