网页中嵌入pdf格式文件
程序员文章站
2022-05-28 16:54:11
...
在网页中直接显示pdf格式的文件方便阅读。但是如果文件较大加载速度会很慢,另外如果客户端没有安装pdf阅读插件的话,也就看不了了,不过还是贴出来了,各取所需吗。(1.pdf要改成自己的pdf文件路径插入到页面文件中)
- <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>
标准浏览器中:
- <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区域
- <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:
- <!--[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控制显示隐藏
- /* 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; }
/**/
- <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>