Open PDF files using js plug-ins

Source: Internet
Author: User
Tags pdfobject

Open PDF files using js plug-ins

Requirement: PDF files must be displayed on JSP pages. The following two solutions are provided. The JS plug-in is good.

Two solutions: a direct link that treats a PDF file as an IMG file, similar to the form of <a href = ""/>. The link is as follows:

 

The Code is as follows:

<Frame src = "pdf file address"> </frame>

 

 

Another method is to use js plug-ins.

There are many js plug-ins for reading pdf files, such as pdf. js: A technical prototype is mainly used to display PDF documents on the HTML5 platform without any local technical support. jsPDF: an open-source library for generating PDF files using Javascript language (not supported by IE currently );

Simple and Easy-to-use JavaScript plug-in: PDFObject. js is a JavaScript library used to dynamically embed PDF files in HTML.

The effect is as follows:

 

 

PDFObject. js has been upgraded to 1.2 and supports IE9.

PDFObject. js purpose: Sometimes you need a little JavaScript. When you do, try PDFObject.

Let's take a look at the few js codes:

 

 

The Code is as follows:

<Script type = "text/javascript">

Window. onload = function (){

Var success = new PDFObject ({url: "sampleess"}). embed ();

};

</Script>

 

 

OK. Write the address to the correct address.

What if I load a pdf file in a div? Check the official website and find that the embed () method can have parameters. If there is no parameter, it refers to the body. If there is a parameter, It is a specific location.

 

 

The Code is as follows:

<Script type = "text/javascript">

Window. onload = function (){

Var success = new PDFObject ({url: "sampleess"}). embed ("div id ");

};

</Script>

 

 

Of course, you can further set parameters, such as how many seconds you want to preview, css, and css.

 

 

 

Related Article

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.