Use Psd.js to enable PDF files to be read both on the web and on the mobile side

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.