如何在jsp中的小框中查看pdf文件

时间:2013-10-07 10:23:38

标签: java jsp-tags

我想在jsp的小方框中查看pdf文件,没有任何选项,如下载,view.please给出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();
}

and already i done download pdf file use this code 

2 个答案:

答案 0 :(得分:0)

您可以使用PDFObject。这需要Javascript。您还可以使用Object标记,如下所示

<object data="yourfile.pdf" type="application/pdf" width="100%" height="100%">
  <p>Alternative text - include a link <a href="yourfile.pdf">yourfile</a></p>
</object>

答案 1 :(得分:0)

你可以试试这个。我不确定。但你可以试试。

 TINY.box.show({url: "your url", post: "mainid=" + varMainId + "&subid=" + yourID);