Displaying a PDF in an ASP.NET Web Forms application |
Top Previous Next |
You are here: Gnostice PDFOne .NET Developer Guide > Getting Started > Displaying a PDF in an ASP.NET Web Forms application
Displaying a PDF in an ASP.NET Web Forms application In this topic, you will learn about creating a simple PDF viewer in an ASP.NET Web application.
Here are the steps: 1.Open Visual Studio. 2.Create an empty ASP.NET Web Application project. 3.Open the Web.config file of the project and add the following lines before the system.web closing tag.
<httpHandlers> <add verb="GET,POST" path="PDFViewer.axd" type="Gnostice.PDFOne.Controls.Web.PDFViewer, Gnostice.PDFOne.Controls.Web" /> </httpHandlers> <httpRuntime executionTimeout="110" maxRequestLength="901196" />
4.Add this system.webServer below the system.web tag.
<system.webServer> <validation validateIntegratedModeConfiguration="false" /> <handlers accessPolicy="Read, Write, Script, Execute"> <remove name="SPImage" /> <add name="SPImage" verb="GET,POST" path="PDFViewer.axd" type="Gnostice.PDFOne.Controls.Web.PDFViewer, Gnostice.PDFOne.Controls.Web" /> </handlers> </system.webServer>
5.In Solution Explorer, add a reference to the following DLLs: 1.Gnostice.PDFOne.Controls.Web.dll 2.Gnostice.PDFOne.dll 3.Gnostice.XtremeFontEngine.dll 4.Gnostice.XtremeImageEngine.dll 6.Select these DLLs and set their "Copy Local" property to true to ensure that your Web application is self-contained. 7.In the Solution Explorer, right-click the project and choose to add an "App_Data" folder. 8.Copy a PDF file named sample_doc.pdf in the App_Data folder. 9.Add a new Web Form to the project. 10.Add jQuery plugin to the HEAD section of the web page source. 11.Switch to the Design view. 12.Open the Toolbox and navigate to the PDFOne tab. If it is not already there, create a new one with the Gnostice.PDFOne.Controls.Web.dll. 13.From the AJAX Extensions tab, drag and drop a ScriptManager component to the form. 13.Drag and drop a Web.PDFViewer component on the form. Resize the control to your requirements. 14.Right-click on the form and select "View Code". 15.Set the "page load" event handler as follows (but with the correct license key).
PDFViewer1.ActiveLicense("your-license-key"); PDFViewer1.LoadDocument(Server.MapPath(".") + "\\App_Data\\sample.pdf");
16.Save the project and run it. The PDF document will be displayed in the web page. |