Reason: Recently developed projects, you need to show the "* * University * * Annual Employment Quality Report", because the project is mobile priority, using bootstrap for the front-end development.
Experience: WEB-side implementation is relatively easy, but to the mobile side does not show, later Baidu a bit of information, found that pdf.js can display PDF files on the mobile side, and began to understand.
Portal: pdf.js, link address for Pdf.js website Introductory Learning section.
Instance code:
HTML front-end Display section
<!--PDF Display--<p align= "center" ><canvas id= "The-canvas" ></canvas></p><!-- PDF Control Area--><div id= "Pdf-content" > <button id= "prev" class= "btn btn-success" > Previous </button> < Button id= "Next" class= "Btn btn-primary" > Next </button> <button class= "btn btn-info" > Pages: <span id= " Page_num "></span>/<span id=" Page_count "></span></button> <a class=" Btn Btn-danger Hidden-xs "id=" quanping "href=" "target=" _blank "style=" margin-top:0px; " > Full Screen view </a></div>
JS Introduction
<script src= "/public/js/pdf.js" ></script><script src= "/public/js/jquery.min.js" ></script ><script src= "/public/js/pdf-worker.js" ></script>
Pdf.js, Pdf-worker.js, JQ (Baidu Network Disk): Link: https://pan.baidu.com/s/1DLk6yWt_HKtpjFNOambh4Q Password: X7ZC
Through the lower JS, in the btnutl to get the background pass the PDF path, and assign the path to the quanping, one for the full screen can open the PDF file directly, the second is the Pdf.js file to obtain the path to the PDF.
<script>/* domain */var http = location.protocol;/* protocol */var yuming = Window.location.host;var quanping = Document.getEle Mentbyid (' quanping '); var btnurl = http + "//" + yuming + "/public/uploads/baogao/20180425/5ae028774d38d.pdf"; Quanping.setattribute (' href ', btnurl);</script>
The final results are as follows
Web-side
Mobile side
Use Psd.js to enable PDF files to be read both on the web and on the mobile side