Home  >  Article  >  Web Front-end  >  How to use H5 to preview documents in PDF format

How to use H5 to preview documents in PDF format

php中世界最好的语言
php中世界最好的语言Original
2018-01-19 09:23:465214browse

This time I will show you how to use H5 to preview PDF format documents. What are the precautions for previewing PDF format documents with H5. Here are practical cases, 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">
    <div id="tmPlayer" class="tmPlayer" style="height: 557px; width: 100%; height: 100%"></div>
 
    <script type="text/javascript">
        $(&#39;.tmPlayer&#39;).html(&#39;<iframe frameBorder="0" scrolling="no" src="/Scripts/plugins/pdfjs/generic/web/viewer.html?file=&#39; +
            var_filepath +
            &#39;" style="width:100%; height:100%;"></iframe>&#39;);
    </script>
 
</body>
</html>

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

Related reading:

How to implement table mouse drag sorting in HTML

New features of HTML 5 How to use

#HtmlHow to achieve the report effect of dynamically displaying color blocks

The above is the detailed content of How to use H5 to preview documents in PDF format. 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