H5怎么实现在线预览PDF


本文摘自PHP中文网,作者php中世界最好的语言,侵删。

这次给大家带来H5怎么实现在线预览PDF,H5实现在线预览PDF的注意事项有哪些,下面就是实战案例,一起来看一下。

简介

PDF.js is a Portable Document Format (PDF) viewer that is built with HTML5.

PDF.js is community-driven and supported by Mozilla Labs. Our goal is to create a general-purpose, web standards-based platform for parsing and rendering PDFs.

开源地址:https://github.com/mozilla/pdf.js

下载后不能直接使用,需要重新构建,不熟悉将会非常麻烦

构建好的程序包:build_jb51.rar

示例

引用文件,直接复制下文可以直接使用

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

<!DOCTYPE html>

<html>

<head>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

    <title>课程详情</title>

    <style type="text/css">

    </style>

    <script src="~/Scripts/jquery-1.10.2.min.js"></script>

    <script src="~/Scripts/plugins/pdfjs/pdf.js"></script>

    <script src="~/Scripts/plugins/pdfjs/pdf.worker.js"></script>

    <script type="text/javascript">

        var var_filepath = decodeURIComponent("@filepath");//不能跨域

        var var_win_height = $(window).height();

        $(document).ready(function () {

            resetPlayerSize();

        });

        $(window).resize(function () {

            resetPlayerSize();

        });

        function resetPlayerSize() {

            var_win_height = $(window).height();

            $(".tmPlayer").css({ "height": var_win_height + "px" });

        }

    </script>

</head>

<body style="margin: 0;overflow: hidden">

    <p id="tmPlayer" class="tmPlayer" style="height: 557px; width: 100%; height: 100%"></p>

    <script type="text/javascript">

        $('.tmPlayer').html('<iframe frameBorder="0" scrolling="no" src="/Scripts/plugins/pdfjs/generic/web/viewer.html?file=' +

            var_filepath +

            '" style="width:100%; height:100%;"></iframe>');

    </script>

</body>

</html>

相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!

阅读剩余部分

相关阅读 >>

HTML5手机端页面缩放问题的解决详解

flash和HTML5的区别有哪些

HTML5 webworkers防止浏览器假死的示例代码分享

采用HTML5+signalr2.0(.net)实现原生web视频的代码分享

HTML5中如何制作搜索栏

html中序列化标签的简单介绍(代码实例)

h5手机扫码怎么实现

浅谈前端的正则表达式

HTML5盒子模型的使用方法

HTML5移动应用现状谈发展趋势的详细介绍

更多相关阅读请进入《HTML5》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...