PDF viewer in Asp.Net

笑着哭i 提交于 2019-12-11 19:17:15

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!