如何在html中在线预览pdf文件?

方法1:使用 jquery js 库

1.引入 jquery-3.1.1.min.js 和 jquery.media.js 两个js文件,下载保存到本地
下载连接:jquery-3.1.1.min.js jquery.media.js
2.在html页引入js脚本:

<script type="text/javascript" src="javascripts/jquery/jquery-3.1.1.min.js"></script>
<script type="text/javascript" src="javascripts/jquery/jquery.media.js"></script>

3.页面加载完成需要执行的js代码:

$(function() {
    $('a.media').media({width:'1200px', height:'900px'});
});

4.在需要预览的区域加上html代码:

<div>
    <a class="media" href="doc/乔布斯传中文版.pdf"></a>
</div>

样例预览 代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="乔布斯传中文版:在线阅读" />
<meta name="description" content="乔布斯传中文版:在线阅读" />
<title>乔布斯传中文版</title>
<script type="text/javascript" src="javascripts/jquery/jquery-3.1.1.min.js"></script>
<script type="text/javascript" src="javascripts/jquery/jquery.media.js"></script>
<script type="text/javascript">
    $(function() {
        $('a.media').media({width:'1200px', height:'900px'});
    });
</script>
</head>
<body background="images/bj.jpg">
 
<center>
<div>
    <a class="media" href="doc/乔布斯传中文版.pdf"></a>
</div>
</center>
</body>
</html>     

方法2: 使用 pdfobject js 库

1.下载 pdfobject.js 插件
下载连接:pdfobject.js 2.引入 pdfobject.js 插件

<script type="text/javascript" src="javascripts/pdfobject.js"></script>

3.在 window.onload 中 实现具体 pdf 文档的显示:

<script type="text/javascript">
    window.onload = function() {
        PDFObject.embed(
            "http://localhost/other/doc/乔布斯传中文版.pdf",
            "#pdf"
        );
    };
</script>

样例预览 代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="乔布斯传中文版:在线阅读" />
<meta name="description" content="乔布斯传中文版:在线阅读" />
<title>乔布斯传中文版</title>
<script type="text/javascript" src="javascripts/pdfobject.js"></script>
</head>
<body background="images/bj.jpg">
<script type="text/javascript">
    window.onload = function() {
        PDFObject.embed(
            "http://localhost/other/doc/乔布斯传中文版.pdf",
            "#pdf"
        );
    };
</script>
<center>
<div id="pdf" style="width: 1200px;height: 900px;">
</div>
</center>
</body>
</html>

摘自:如何在html中在线预览pdf文件?如何在html中在线预览pdf文件?icon-default.png?t=N2N8https://www.jxxgcyc.top/school/help001.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值