在jsp上顯示pdf||網頁直接開啟PDF 在IE中顯示pdf文檔的方法及參數設定

來源:互聯網
上載者:User

         一:在jsp上顯示pdf  

http://hi.baidu.com/velercy/blog/item/be708dea2c3236ddd439c9b4.html

<%@ page language="java" import="java.util.*,java.io.*"pageEncoding="ISO-8859-1"%><%String path = request.getContextPath();String basePath = request.getScheme() + "://"    + request.getServerName() + ":" + request.getServerPort()    + path + "/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head>   <base href="<%=basePath%>"></head><%   out.clear();   out = pageContext.pushBody();   response.setContentType("application/pdf");   try {    String strPdfPath = new String("D://200701010001.PDF");    //判斷該路徑下的檔案是否存在    File file = new File(strPdfPath);    if (file.exists()) {     DataOutputStream temps = new DataOutputStream(response       .getOutputStream());     DataInputStream in = new DataInputStream(       new FileInputStream(strPdfPath));     byte[] b = new byte[2048];     while ((in.read(b)) != -1) {      temps.write(b);      temps.flush();     }     in.close();     temps.close();    } else {     out.print(strPdfPath + " 檔案不存在!");    }   } catch (Exception e) {    out.println(e.getMessage());   }%><body>   <br></body></html>        

        二: 如果訪問者的電腦上沒有裝acrobat reader,直接用iframe或者直接用連結開啟,那就不是開啟文檔,而是直接下載了,為了防止下載,想像到媒體檔案的播放方式,加上一些官方的docs,考慮用用object標籤使用pdf外掛程式嵌入ie中,結果可行。轉載自:http://hi.baidu.com/cowboy_jia/blog/item/9bf4a6cb2e736afa52664fba.html

<HTML>    <HEAD>        <META http-equiv="Content-Type" content="text/html; charset=gb2312">        <META http-equiv="Content-Style-Type" content="text/css">        <META http-equiv="Content-Script-Type" content="text/javascript">        <TITLE>Checking if Acrobat Reader installed (IE4+)...</TITLE>        <SCRIPT for="window" event="onload"<!--            document.all [                         document.all.PDFNotKnown ? "IfNoAcrobat" : "IfAcrobat"                         ] .style.display = "block";        //--></SCRIPT>    </HEAD>    <BODY>        <NOSCRIPT>            Cannot determine if you have Acrobat Reader (or the full Acrobat)            installed <FONT size="-1">(because JavaScript is unavailable or             turned off)</FONT>.        </NOSCRIPT>        <DIV id="IfNoAcrobat" style="display:none">            <a href="http://get.adobe.com/cn/reader/">你需要先安裝Adobe Reader才能正常瀏覽檔案,請點擊這裡下載Adobe Reader.</a>         </DIV>        <OBJECT type="application/pdf" width=0 height=0 style="display:none">            <DIV id="PDFNotKnown" style="display:none"> </DIV>        </OBJECT>   <DIV id=showdivstyle="Z-INDEX: 0; LEFT:10px; WIDTH: 990px; POSITION: absolute; TOP: -8px; HEIGHT: 10px"><object classid="clsid:CA8A9780-280D-11CF-A24D-444553540000" width="990" height="700" border="0" top="-10" name="pdf"> <param name="toolbar" value="false"><param name="_Version" value="65539"><param name="_ExtentX" value="20108"><param name="_ExtentY" value="10866"><param name="_StockProps" value="0"><param name="SRC" value="MXL.pdf"></object></DIV></BODY></HTML>

 

三:在網頁中直接顯示pdf格式的檔案方便閱讀。但是如果檔案較大載入速度會很慢,另外如果用戶端沒有安裝pdf閱讀外掛程式的話,也就看不了了,不過還是貼出來了,各取所需嗎。(1.pdf要改成自己的pdf檔案路徑插入到分頁檔中)http://hi.baidu.com/xcb521/blog/item/69f0b48aea5377d8fd1f1000.html

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>   <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>   <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>   <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]-->   <!--[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; }    /**/   /* 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>

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.