1-使用 Runtime.getRuntime().exec("C:\\Program Files (x86)\\Adobe\\Reader 11.0\\Reader\\AcroRd32.exe E:\\11.pdf");就可以
前面为打开文件的程序路径、后面为文件的路径。
2-jsp上显示pdf
01.<%@ page language="java" import="java.util.*,java.io.*" 02.pageEncoding="ISO-8859-1"%> 03.<% 04.String path = request.getContextPath(); 05.String basePath = request.getScheme() + "://" 06. + request.getServerName() + ":" + request.getServerPort() 07. + path + "/"; 08.%> 09. 10.<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 11.<html> 12.<head> 13. <base href="<%=basePath%>"> 14.</head> 15.<% 16. out.clear(); 17. out = pageContext.pushBody(); 18. response.setContentType("application/pdf"); 19. 20. try { 21. String strPdfPath = new String("D://200701010001.PDF"); 22. //判断该路径下的文件是否存在 23. File file = new File(strPdfPath); 24. if (file.exists()) { 25. DataOutputStream temps = new DataOutputStream(response 26. .getOutputStream()); 27. DataInputStream in = new DataInputStream( 28. new FileInputStream(strPdfPath)); 29. 30. byte[] b = new byte[2048]; 31. while ((in.read(b)) != -1) { 32. temps.write(b); 33. temps.flush(); 34. } 35. 36. in.close(); 37. temps.close(); 38. } else { 39. out.print(strPdfPath + " 文件不存在!"); 40. } 41. 42. } catch (Exception e) { 43. out.println(e.getMessage()); 44. } 45.%> 46.<body> 47. <br> 48.</body> 49.</html>
3.用object标签使用pdf插件嵌入ie中
01.<HTML> 02. <HEAD> 03. <META http-equiv="Content-Type" content="text/html; charset=gb2312"> 04. <META http-equiv="Content-Style-Type" content="text/css"> 05. <META http-equiv="Content-Script-Type" content="text/javascript"> 06. <TITLE>Checking if Acrobat Reader installed (IE4+)...</TITLE> 07. <SCRIPT for="window" event="onload" 08.<!-- 09. document.all [ 10. document.all.PDFNotKnown ? "IfNoAcrobat" : "IfAcrobat" 11. ] .style.display = "block"; 12. //--></SCRIPT> 13. </HEAD> 14. <BODY> 15. <NOSCRIPT> 16. Cannot determine if you have Acrobat Reader (or the full Acrobat) 17. installed <FONT size="-1">(because JavaScript is unavailable or 18. turned off)</FONT>. 19. </NOSCRIPT> 20. <DIV id="IfNoAcrobat" style="display:none"> 21. <a href="http://get.adobe.com/cn/reader/">你需要先安装Adobe Reader才能正常浏览文件,请点击这里下载Adobe Reader.</a> 22. 23. </DIV> 24. <OBJECT type="application/pdf" width=0 height=0 style="display:none"> 25. <DIV id="PDFNotKnown" style="display:none"> </DIV> 26. </OBJECT> 27. <DIV id=showdiv 28.style="Z-INDEX: 0; LEFT:10px; WIDTH: 990px; POSITION: absolute; TOP: -8px; HEIGHT: 10px"> 29.<object classid="clsid:CA8A9780-280D-11CF-A24D-444553540000" width="990" height="700" border="0" top="-10" name="pdf"> 30.<param name="toolbar" value="false"> 31.<param name="_Version" value="65539"> 32. 33.<param name="_ExtentX" value="20108"> 34. 35.<param name="_ExtentY" value="10866"> 36. 37.<param name="_StockProps" value="0"> 38. 39.<param name="SRC" value="MXL.pdf"> 40.</object> 41.</DIV> 42.</BODY> 43.</HTML>
4-在网页中直接显示pdf格式的文件
Html代码
- <object classid="clsid:CA8A9780-280D-11CF-A24D-444553540000" width="800" height="1050" border="0">
- <param name="_Version" value="65539">
- <param name="_ExtentX" value="20108">
- <param name="_ExtentY" value="10866">
- <param name="_StockProps" value="0">
- <param name="SRC" value="1.pdf">
- </object>
标准浏览器中:
Java代码- <object data="1.pdf" type="application/pdf" width="300" height="200">
- alt : <a href="1.pdf">test.pdf</a>
- </object>
IE7.0以上版本的浏览器中可用如下方法,低版本的IE会显示两个Object区域
Java代码- <object classid="clsid:CA8A9780-280D-11CF-A24D-444553540000" width="800" height="1050" border="0">
- <param name="_Version" value="65539">
- <param name="_ExtentX" value="20108">
- <param name="_ExtentY" value="10866">
- <param name="_StockProps" value="0">
- <param name="SRC" value="1.pdf">
- <object data="1.pdf" type="application/pdf" width="300" height="200">
- alt : <a href="1.pdf">test.pdf</a>
- </object>
- </object>
低版本浏览器中的处理方法1:
Java代码- <!--[if IE]>
- <object classid="clsid:CA8A9780-280D-11CF-A24D-444553540000" width="800" height="1050" border="0">
- <param name="_Version" value="65539">
- <param name="_ExtentX" value="20108">
- <param name="_ExtentY" value="10866">
- <param name="_StockProps" value="0">
- <param name="SRC" value="1.pdf">
- </object>
- <![endif]-->
- <!--[if !IE]> <!-->
- <object data="1.pdf" type="application/pdf" width="800" height="1050">
- alt : <a href='http://get.adobe.com/cn/reader'>Adobe Reader.pdf</a>
- </object>
- <!--<![endif]-->
低版本浏览器中的处理方法2:通过CSS控制显示隐藏
Html代码
- /* hides the second object from all versions of IE */
- * html object.hiddenObjectForIE { display: none; }
- /* display the second object only for IE5 Mac */
- /* IE Mac \*//*/
- * html object.hiddenObjectForIE { display: inline; }
- /**/
Html代码
- <object classid="clsid:CA8A9780-280D-11CF-A24D-444553540000" width="800" height="1050" border="0">
- <param name="_Version" value="65539">
- <param name="_ExtentX" value="20108">
- <param name="_ExtentY" value="10866">
- <param name="_StockProps" value="0">
- <param name="SRC" value="1.pdf">
- <object data="1.pdf" type="application/pdf" width="300" height="200" class="hiddenObjectForIE">
- alt : <a href="1.pdf">test.pdf</a>
- </object>
- </object>
据说用 itext 或者 pdf Rentender 也可以实现,没有实践 留待下次细说。