利用流在客户端IE内嵌显示PDF




  1.生成临时文件
Java代码
File filepdf = null;  
filepdf = File.createTempFile("test", ".pdf", new File(sPdfDir));/*sPdfDir是输出目录*/ 

File filepdf = null;
filepdf = File.createTempFile("test", ".pdf", new File(sPdfDir));/*sPdfDir是输出目录*/

   2.利用流生成PDF 利用Servlet

Java代码
HttpServletResponse response = null;  
response.setContentType("application/pdf; charset=UTF-8");  
response.setHeader("Content-Disposition", "inline" + "; filename=\"");  
/*inline内嵌显示PDF,如果需要下载而不是在IE中看的话,则是response.setHeader("Content-Disposition", "attachment" + "; filename=\"");*/ 
ServletOutputStream out = response.getOutputStream();/*输出流*/ 
FileInputStream fis = new FileInputStream(filepdf);/*输入流*/ 
byte[] buf = new byte[fis.available()];  
fis.read(buf);/*读入文件流*/ 
out.write(buf);/*写到输出流里去*/ 
fis.close();  
response.flushBuffer();  
//filepdf.delete(); 

http://www.cnblogs.com/hardrock/archive/2006/02/23/336397.html

你可能感兴趣的:(html,servlet,IE)