public void findPdf() throws IOException{
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("application/pdf");
FileInputStream in = new FileInputStream(new File(“c:/测试.pdf”));
OutputStream out = response.getOutputStream();
byte[] b = new byte[512];
while ((in.read(b))!=-1) {
out.write(b);
}
out.flush();
in.close();
out.close();
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("application/pdf");
FileInputStream in = new FileInputStream(new File(“c:/测试.pdf”));
OutputStream out = response.getOutputStream();
byte[] b = new byte[512];
while ((in.read(b))!=-1) {
out.write(b);
}
out.flush();
in.close();
out.close();
}
经测试,火狐和谷歌可以展示,会在整个页面显示,会将页面替换成整个pdf的视图页面
所以用function方法开个一个新的窗口
function finPdf(){
window.open(url, "_blank","top=200,left=200,height=600,width=800,status=yes,toolbar=1,
window.open(url, "_blank","top=200,left=200,height=600,width=800,status=yes,toolbar=1,
menubar=no,location=no,scrollbars=yes");
}
}
本文介绍了一种通过Java Web应用实现PDF文件在线预览的方法。该方法利用Servlet API读取本地PDF文件,并将其作为HTTP响应发送给浏览器,使得火狐和谷歌等现代浏览器能够直接在新窗口中打开并展示PDF内容。
1959

被折叠的 条评论
为什么被折叠?



