Home  >  Article  >  Web Front-end  >  How to preview PDF online in H5

How to preview PDF online in H5

php中世界最好的语言
php中世界最好的语言Original
2018-03-27 11:32:1810591browse

This time I will show you how to preview PDF online in H5. What are the precautions for H5 to preview PDF online. The following is a practical case, let’s take a look.

Introduction

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.

Open source address:https://github.com/ mozilla/pdf.js

cannot be used directly after downloading and needs to be rebuilt. If you are not familiar with it, it will be very troublesome

Built package: build_jb51.rar

Example

Quote the file, copy the following directly and use it directly

<!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=&#39; +
            var_filepath +
            &#39;" style="width:100%; height:100%;"></iframe>');
    </script>
</body>
</html>

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

Detailed explanation of Drag and Drop in H5

How to call APP in H5 page

The above is the detailed content of How to preview PDF online in H5. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn