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.