欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

HTML5在线预览PDF的示例代码

程序员文章站 2022-06-30 11:14:34
本篇文章主要介绍了HTML5在线预览PDF的示例代码,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧 ... 17-09-14...

简介

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.

开源地址:

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

构建好的程序包:

示例

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

<!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"> 
    <div id="tmplayer" class="tmplayer" style="height: 557px; width: 100%; height: 100%"></div>

    <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>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。