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文档
最新推荐文章于 2022-07-04 15:59:49 发布