zoukankan      html  css  js  c++  java
  • 移动端展示pdf(在线打开pdf)

    需求:在手机微信浏览器或者其他浏览器中打开pdf

    准备:前端插件:查找pdf.js  官网地址:http://mozilla.github.io/pdf.js/ 在官网中下载demo

    注释:pdf的demo 必须在web项目中打开,所以必须得部署web项目

    官方API,如下

    画方框的文件目录结构,请不要更改,直接在下载的demo中拷贝出来

    demo 地址:

    web 项目中文件的目录

    testPdf.jsp

    <%@ page language="java" contentType="text/html; charset=utf-8"
        pageEncoding="ISO-8859-1"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Insert title here</title>
    </head>
    <body>
            <button>在线浏览pdf</button>
    </body>
    <script type="text/javascript">
        function browserPdf()
        {
            $.ajax({
                url: 'http://192.168.1.110:8060/mypdf/testPDF.pdf,
                type: "get",
                success: function(xhr, data){
                    if (navigator.userAgent.indexOf('Android') > -1) {
                        //判断移动端是android 还是ios ,若是android 则要借助pdf插件
                        window.location.href = "http://192.168.1.110:8060/js/web/viewer.html?file="+url;
                    } else {
                        //ios直接打开pdf
                        //window.location.href = url;
                        window.location.href = "http://192.168.1.110:8060/js/web/viewer.html?file="+url;
                    }
                },
                error: function(){
                            //window.location.href = '${ctx}/core/user.androidPdf.do?mid='+mid+"&name="+storagename+"&realname="+realname;
                    window.location.href = "http://192.168.1.110:8060/js/web/viewer.html?file="+url;
                }
            });
        }
        
        
    </script>
    </html>

     项目启动,之后进行访问

    效果图:

  • 相关阅读:
    165. Compare Version Numbers
    164. Maximum Gap
    3、桶排序
    162. Find Peak Element
    160. Intersection of Two Linked Lists
    155. Min Stack
    154. Find Minimum in Rotated Sorted Array II
    153. Find Minimum in Rotated Sorted Array
    Linux/Unix系统编程手册 第二章:基本概念
    Linux/Unix系统编程手册 第一章:历史和标准
  • 原文地址:https://www.cnblogs.com/blogxiao/p/8178395.html
Copyright © 2011-2022 走看看