您的位置:首页 > 其它

Vaadin——打开PDF文档

2015-07-27 11:34 253 查看
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