View PDF Files From Web Browser In C#


The basic idea is to create a preview of PDF files from web browser in C#. After looking at many places on the internet, I found a wonderful PDF document viewer library,Spire.PDFViewer for ASP.NET. It allows developers to load and view any PDF documents from web browser and there is no need to install Adobe Reader or any other third party software on your system. It is pure .NET library and we can call to use the Spire.PDFViewer.Asp.dll directly to our .NET applications.


This article will show you how to view a PDF file online from the web browser and then we will manage the PDF files, such as switch to the target PDF page, zoom in and zoom out the PDF files. I will use a Web Application in Visual Studio, for example to show you the steps of how to achieve the functions of viewing the PDF files from the web.

Using the code


Create an ASP.NET Web Application named PDFViewer in Visual Studio. Then add a new web Form to it and also add the Spire.PDFViewer .dll files from the bin folder as the references.



Step 2: Add the PDFViewer control and the PDFDocumentViewer control into toolbox.


Step 3: Drag the PDFViewer control from toolbox into WebForm1.aspx.


Step 4: Double click the Default.aspx.cs, and use the following one line of code to load a PDF file and view it from the web browser:

  1. this.PdfViewer1.LoadFromFile("File\\Sample.pdf");  
After debugging it, we will view the PDF file online from the web browser.


From the top toolbar, we can find that it is easy for us to switch to the target PDF page, turning to the previous page, the next page, the first page, and the last page, or even switch to any existing target PDF page. We can set to fit PDF page, zoom out, zoom in the PDF files, and we can also use the hand tool to go to the desired position.

If you don’t want to use the above features on the top toolbar, we can drag PDFDocumentViewer control from toolbox into WebForm1.aspx to view the PDF files directly.
  1. PdfDocumentViewer1.LoadFromFile("File\\Sample.pdf");  


Spire.PDFViewer is a powerful PDF Viewer API for developers to load the PDF document from file and view the PDF files on the web. It is easy to use and totally independent. It is worthy your try on it.


Up Next
    Ebook Download
    View all
    View all