Two options: one is a direct link, treating the pdf file as an img file, similar to <a href=""/>, linking like this:
Copy the code code as follows:
<frame src="pdf file address"></frame>
Another way: 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 an open source library that uses Javascript language to generate PDF ( IE is not supported 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.
PDFObject.js Purpose: Sometimes you need a little JavaScript. When you do, try PDFObject.
Let’s take a look at the very few js codes:
Copy the code code as follows:
<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 if I load a pdf in a div? 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.
Copy the code code as follows:
<script type="text/javascript">
window.onload = function (){
var success = new PDFObject({ url: "sample.pdf" }).embed("div's id");
};
</script>
Of course, you can also set further parameters, such as how many seconds you want to preview, with css, without css, etc.