问题
I have a list of documents at server. and want to develop a page where the list of documents will be displayed as hyperlinks in left panel/div and while click on a link. the right panel displays the corresponding PDF document from server.
can anybody help me out to develop the same using jquery or javascript?
thanks in advance
i tried below code based on some articles i read Script :
<script language="javascript" type="text/javascript"> function previewPdf(url, target) { var div = document.getElementById(target); var obj = document.createElement("<embed style='width:939px; height:736px;' frameborder='0' src='" + url +"')></embed>"); div.appendChild(obj); } </script>
Body :
<body style="height: 741px">
<form id="form1" runat="server">
<div id="div1" style="float:left; width: 20%; text-align: left; height: 100%; border-width:2px;">
<button onclick="previewPdf('Documents/Accomodation.pdf','div2')">Accomodation</button>
<br />
<button onclick="previewPdf('Documents/Insurance.pdf','div2')">Insurance</button>
<br />
<button onclick="previewPdf('Documents/Air Ticket.pdf','div2')">Air Ticket.pdf</button>
<br />
</div>
<div id="div2" style="float:right;width: 80%; text-align: left; height: 100%; border-color:Maroon">
</div>
</form>
</body>
but it doesnt replace the 'div2' with the content[pdf].
回答1:
Here is the javascript for displaying pdf in html5 format. You will need edit it as per your requirements. https://github.com/mozilla/pdf.js
回答2:
If you can use a ASP.NET PDF viewer component, then here is how it is done with Gnostice PDFOne .NET.
PDFViewer1.ActiveLicense("your-license-key");
PDFViewer1.LoadDocument(Server.MapPath(".") + "\\App_Data\\sample.pdf");
DISCLAIMER: I work for Gnostice.
来源:https://stackoverflow.com/questions/16298396/pdf-viewer-in-asp-net