web中瀏覽PDF文件


 1.在web中瀏覽pdf文件。

 2.支持大多數主流瀏覽器,包括IE8

 3.參考網址:

https://pdfobject.com/

http://mozilla.github.io/pdf.js/

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="viewfile.aspx.cs" Inherits="Web.Student.viewfile" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script src="../Script/jquery-1.7.2.min.js"></script>
    <link rel="resource" type="application/l10n" href="../Plugin/pdfjs/web/locale/locale.properties" />
    <script type="text/javascript" src="../Plugin/pdfobject/pdfobject.js"></script>
    <title>文檔預覽</title>

    <script type="text/javascript">
        $(function () {
            $("#file-container").height($(window).height() - 20);
            $(window).resize(function () {
                $("#file-container").height($(window).height() - 20);
            });

            viewpdf();

        });

        var viewpdf = function () {var options = {};
            if (PDFObject.supportsPDFs) {
                //表示瀏覽器支持內聯PDF
                console.log("Yay, this browser supports inline PDFs.");
                options = {
                    page: 1,//默認顯示第幾頁
                    fallbackLink: "<p>This is a <a href='<%=FPath %>'>fallback link</a></p>"
                };
            } else {
                //表示瀏覽器不支持內聯PDF
                console.log("Boo, inline PDFs are not supported by this browser");
                options = {
                    pdfOpenParams: {
                        navpanes: 0,
                        toolbar: 0,
                        statusbar: 0,
                        view: "FitV",
                        pagemode: "none",//thumbs=顯示縮略圖;none=不顯示縮略圖。
                        locale: "zh-CN",
                        page: 1//默認顯示第幾頁
                    },
                    forcePDFJS: true,
                    PDFJS_URL: "../Plugin/pdfjs/web/viewer.html"
                };
            }
            var mypdf = PDFObject.embed("<%=FPath %>", "#file-container", options);
        };

    </script>
</head>
<body style="margin:0;padding:0;">
    <div id="file-container" style="width: 100%; height: 500px;">
    </div>
</body>
</html>

 引用的js文件下載地址:http://download.csdn.net/detail/wz122889488/9850544


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM