Requirement: To display pdf files in JSP web pages, two options are given below. The JS plug-in is good.
Two options: one is a direct link, treating the pdf file as an img file, similar In this form, link like this:
<frame src="pdf文件的地址"></frame>
Another one: use js plug-in.
There are many js plug-ins for reading PDF files, such as: pdf.js: is a technical prototype mainly used to display PDF documents on the HTML5 platform without any local technical support; jsPDF: is a Javascript language An open source library for generating PDF (not supported by IE yet);
A relatively simple and easy-to-use js plug-in: PDFObject.js, which is a JavaScript library used to dynamically embed PDF documents in HTML.
The effect is as follows:
PDFObject.js has been upgraded to 1.2 and can support IE9.
Purpose of PDFObject.js: Sometimes you need a little JavaScript. When you do, try PDFObject.
Let’s take a look at the very little js code:
<script type="text/javascript"> window.onload = function (){ var success = new PDFObject({ url: "sample.pdf" }).embed(); }; </script>
OK, that's it. Just write the address correctly.
What should I do if I load pdf in a certain p? Looking at the official website, I found that the embed() method can have parameters. No parameters refer to the body, and parameters refer to a specific position.
<script type="text/javascript"> window.onload = function (){ var success = new PDFObject({ url: "sample.pdf" }).embed(“p的id”); }; </script>
Of course, you can also set further parameters, such as how many seconds you want to preview, with css, without css, etc.
The above is the entire content of this chapter. For more related tutorials, please visit JavaScript Video Tutorial!