如何在jsp中的pop u窗口中显示pdf文件

时间:2013-10-07 03:13:50

标签: java jsp

我已经完成了我的pdf视图,但现在我只想查看动态pdf文件弹出窗口不下载选项并保存选项所以请在java中给出一些示例 我现在使用这个代码

File f= new File(file);
if(f.exists()){
ServletOutputStream op= response.getOutputStream();
response.reset();
if(check==1){
response.setContentType("application/pdf");
}else{
response.setContentType(content);
                    }
// response.setHeader("Content-disposition","attachment;      filename=" +fileName);
byte[] buf = new byte[4096];
int length;
DataInputStream in = new DataInputStream(new FileInputStream(f));
while ((in != null) && ((length = in.read(buf)) != -1)){
op.write(buf,0,length);
            }
in.close();
op.flush();
op.close();
    }  

1 个答案:

答案 0 :(得分:0)

如果不使用像iText这样的外部库,这是不可能的。

从浏览器下载或保存pdf的功能是PDF中的属性,浏览器中的pdf插件会在浏览器中读取并启用该属性。因此,您必须在PDF本身中禁用该属性,以便浏览器强制执行该约束。

这是一个示例链接 http://www.coderanch.com/t/329511/java/java/revoke-permission-save-copy-PDF