用java打开paf、word..文件

 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代码
  1. <object classid="clsid:CA8A9780-280D-11CF-A24D-444553540000" width="800" height="1050" border="0">  
  2. <param name="_Version" value="65539">  
  3. <param name="_ExtentX" value="20108">  
  4. <param name="_ExtentY" value="10866">  
  5. <param name="_StockProps" value="0">  
  6. <param name="SRC" value="1.pdf">  
  7. </object>  
<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代码
  1. <object data="1.pdf" type="application/pdf" width="300" height="200">   
  2. alt : <a href="1.pdf">test.pdf</a>   
  3. </object>  
<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代码
  1. <object classid="clsid:CA8A9780-280D-11CF-A24D-444553540000" width="800" height="1050" border="0">   
  2. <param name="_Version" value="65539">   
  3. <param name="_ExtentX" value="20108">   
  4. <param name="_ExtentY" value="10866">   
  5. <param name="_StockProps" value="0">   
  6. <param name="SRC" value="1.pdf">   
  7. <object data="1.pdf" type="application/pdf" width="300" height="200">   
  8. alt : <a href="1.pdf">test.pdf</a>   
  9. </object>   
  10. </object>  
<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代码
  1. <!--[if IE]>   
  2. <object classid="clsid:CA8A9780-280D-11CF-A24D-444553540000" width="800" height="1050" border="0">   
  3. <param name="_Version" value="65539">   
  4. <param name="_ExtentX" value="20108">   
  5. <param name="_ExtentY" value="10866">   
  6. <param name="_StockProps" value="0">   
  7. <param name="SRC" value="1.pdf">   
  8. </object>   
  9. <![endif]-->   
  10. <!--[if !IE]> <!-->   
  11. <object data="1.pdf" type="application/pdf" width="800" height="1050">      
  12. alt : <a href='http://get.adobe.com/cn/reader'>Adobe Reader.pdf</a>   
  13. </object>   
  14. <!--<![endif]-->  
<!--[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代码
  1. /* hides the second object from all versions of IE */   
  2.   
  3.   
  4. * html object.hiddenObjectForIE { display: none; }   
  5. /* display the second object only for IE5 Mac */   
  6. /* IE Mac \*//*/   
  7. * html object.hiddenObjectForIE { display: inline; }   
  8. /**/  
/* 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代码
  1. <object classid="clsid:CA8A9780-280D-11CF-A24D-444553540000" width="800" height="1050" border="0">  
  2. <param name="_Version" value="65539">  
  3. <param name="_ExtentX" value="20108">  
  4. <param name="_ExtentY" value="10866">  
  5. <param name="_StockProps" value="0">  
  6. <param name="SRC" value="1.pdf">  
  7. <object data="1.pdf" type="application/pdf" width="300" height="200" class="hiddenObjectForIE">   
  8. alt : <a href="1.pdf">test.pdf</a>  
  9. </object>  
  10. </object>  

据说用 itext 或者 pdf Rentender 也可以实现,没有实践 留待下次细说。

转载于:https://www.cnblogs.com/blogFree/p/3641253.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值