Requirement: Open PDF in mobile browser or other browser
Preparation: Front-end plugin: Find Pdf.js website address: http://mozilla.github.io/pdf.js/Download demo in official website
Note: The PDF demo must be open in a Web project, so you must deploy the Web project
Official API, as follows
Picture The file directory structure of the box, please do not change, directly in the download demo copy out
Demo Address:
A directory of files in a Web project
testpdf.jsp
<%@ Pagelanguage= "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><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"><title>Insert Title here</title></Head><Body> <Button>Browse PDF Online</Button></Body><Scripttype= "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) {//To determine whether the mobile is Android or iOS, if Android is using the PDF plugin window.location.href = "http://192.168 .1.110:8060/js/web/viewer.html?file= "+url; } else {//ios Opens the pdf//window.location.href = URL directly; 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>
Project is started and then accessed
:
Mobile Display PDF (open PDF Online)