Javascript: come utilizzare pdfObject per visualizzare file PDF
Utilizzando la libreria pdfObject è possibile visualizzare file pdf nelle proprie pagine Web con pochissime righe di codice. Vediamo come.
Come utilizzare pdfObject per visualizzare file PDF in Javascript
<html>
<head>
<title>PDFObject example</title>
<script type=”text/javascript” src=”pdfobject.js”></script>
<script type=”text/javascript”>
window.onload = function (){
var myPDF = new PDFObject({ url: “sample.pdf” }).embed();
};
</script>
</head>
<body>
<p>It appears you don’t have Adobe Reader or PDF support in this web
browser. <a href=”sample.pdf”>Click here to download the PDF</a></p>
</body>
</html>
Quest’altro esempio invece fa visualizzare due file PDF in una sola pagina:
<html>
<head>
<style type=”text/css”>
<!–
#pdf1, #pdf2 {
width: 500px;
height: 300px;
margin: 2em auto;
border: 10px solid #6699FF;
}
#pdf1 p, #pdf2 p {
padding: 1em;
}
#pdf1 object, #pdf2 object {
display: block;
border: solid 1px #666;
}
–>
</style>
<script type=”text/javascript” src=”/scripts/pdfobject.js”></script>
<script type=”text/javascript”>
var pdfOpen_params = {
navpanes: 1,
view: “FitH”,
pagemode: “thumbs”
};
var pdfAttributes = {
url: “/pdf/sample.pdf”,
pdfOpenParams: pdfOpen_params
};
window.onload = function (){
var pdf = new PDFObject(pdfAttributes);
pdf.embed(“pdf1”);
var pdf2 = new PDFObject({ url: “/pdf/sample.pdf” });
pdf2.embed(“pdf2”);
};
</script>
</head>
<body>
<h1>Embedding multiple PDFs using PDFObject</h1>
<p>Multiple PDFs can be embedded inside a single HTML document. Note that this is not a recommended practice and may result in buggy behavior from Adobe Reader.</p>
<p> </p>
<div id=”pdf1″>It appears you don’t have Adobe Reader or PDF support in this web browser. <a href=”/pdf/sample.pdf”>Click here to download the PDF</a></div>
<div id=”pdf2″>It appears you don’t have Adobe Reader or PDF support in this web browser. <a href=”/pdf/sample.pdf”>Click here to download the PDF</a></div>
</body>
</html>
Potete scaricare libreria e documentazione qui: http://pdfobject.com/