Getting Started with Spire.PDF, Spire.PDFViewer Library in ASP.Net

by Santhakumar Munuswamy

  Posted on  29 December 2016

  ASP.NET


 

In this article, we will discuss how we can implement the PDF file converting and viewer using Spire.PDF and Spire.PDFViewer Library in ASP.Net. As you all know, it is not an easy job to implement PDF file converter and a viewer at the end user point of you. But, we can do quite easily and simple LOC (lines of code) using Spire.PDF in .NET Application such as a Web and Windows applications. It was basically designed RAD based component to minimize the implementation working hours into our application. 

In this article, we will discuss in details steps as below

  • Learn about background and prerequisite
  • How to install the Spire Library component
  • Create an ASP.Net WebApplication
  • How to add Spire.PDF Viewer component into Visual Studio Tool Box
  • How to add Spire component package to project file
  • How to implement the PDF Viewer using Spire.PDFViewer library
  • How to implement the PDF file conversion using Spire.PDF library

Background

I got an email from E-Iceblue Co., Ltd. to review any one of their products. This is China-based company and vendor of .NET, Silverlight and WPF development components for reading and writing different formats of Office files and PDF development. My first opportunity to review their products at the merit of my knowledge shared through my blog.

First of all, I have decided to review the Spire.PDF, Spire.PDFViewer Library component using ASP.NET application in the end user standpoint. As you all know a PDF is a most important role playing into the application in the reporting standpoint to provide a user-friendly report using PDF file format for easily print and view anywhere and anytime.

Prerequisite

  • Visual Studio 2015
  • Spire.PDF for .Net
  • Spire.PDFViewer for Asp.Net

How to install the Spire Library component

Firstly, you have to download the Spire.PDF file from E-Iceblue Download Center and install them on your PC.

Double Click “spire.pdf_3.8” and this window will be opened, then Click Next button


The License Agreement window will be opened and Click “I accept the terms in the License Agreement” checkbox, then Click Next button.


The Custom Setup window will be opened and you can choose the component and Click Next button


The Ready to install Spire.Pdf window will be opened and Click Install button.


Now, Lets started to installing Spire.Pdf


After, successfully installation of the Spire.Pdf component and Click Finish button


Similarly, you can follow the procedures to install the Spire.PDFViiever component.

Create an ASP.Net Web Application

Open Visual Studio 2015. Go to File menu, point to new and click new project. New Project Window will open, you can select an installed template like “Web” in Visual C# Template and then select the Asp.Net Empty Web Application and type Project Name PDFToolDemo. Choose the project location path and click OK button.


Now you can see the PDFToolDemo project structure, as shown in the screenshot, given below


Go to Solution Explorer, Right PDFToolDemo project, point to Add and Click New Item. Add New Item window will open, you can select the Web Form and Type Name and Click Add button.

How to add Spire.PDF Viewer component into Visual Studio Tool Box

Go to Visual Studio Tool Box, Right Click Add Tab and Type tab name as Spire.PDF section and Right click Choose Items, Choose Toolbox Item window will open and you can verify the active tab as .NET Framework components


Now, you can browse the Spire.PDFViewer.Asp component and attached into the .NET Framework components and then Click Ok button.



How to add Spire component package to project file

Go to the Reference, Right click the Reference and point to Add Reference, followed by Reference Manager. You can browse the Spire.PDF, Spire.PDFViewer and Spire.License and Click Ok button.


Now you can see in the added Reference files as below



How to implement the PDF Viewer using Spire.PDFViewer library

We are going to discuss how to implement the PDF Viewer using Spire.PDFViewer library with the sample application and show the demo in Asp.Net

Using PDFViewer Control

Step 1

When you want to load the Pdf file in the PDF Viewer control, you can add the following line:

<cc1:PdfViewer ID="PdfViewer1" runat="server"></cc1:PdfViewer>

PDFViewer.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>

<%@ Register assembly="Spire.PdfViewer.Asp" namespace="Spire.PdfViewer.Asp" tagprefix="cc1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title></title>

</head>

<body>

    <form id="form1" runat="server">

    <div>        

        <cc1:PdfViewer ID="PdfViewer1" runat="server"></cc1:PdfViewer>    

    </div>      

    </form>

</body>

</html>

PDFViewer.aspx.cs

using System;

 

namespace WebApplication1

{

    public partial class WebForm1 : System.Web.UI.Page

    {

        protected void Page_Load(object sender, EventArgs e)

        {

            if(!IsPostBack)

            {

                this.PdfViewer1.CacheInterval = 1000;

                this.PdfViewer1.CacheTime = 1200;

                this.PdfViewer1.CacheNumberImage = 1000;

                this.PdfViewer1.ScrollInterval = 300;

                this.PdfViewer1.ZoomFactor = 1f;

                this.PdfViewer1.LoadFromFile("Upload/Test.pdf");

            }

        }

    }

}

Step 2

Now, if you can run the sample application, you can see how a PDF Viewer looks, as shown below:


Using PDF Document Viewer control

Step 1

When you want to load the Pdf file in the PDF document viewer control, you can add the following line:

<cc1:PdfDocumentViewer ID="PdfDocumentViewer1" runat="server"></cc1:PdfDocumentViewer>

PDFViever.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="WebApplication1.WebForm2" %>

<%@ Register Assembly="Spire.PdfViewer.Asp" Namespace="Spire.PdfViewer.Asp" TagPrefix="cc1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title></title>

</head>

<body>

    <form id="form1" runat="server">

    <div>

        <cc1:PdfDocumentViewer ID="PdfDocumentViewer1" runat="server"></cc1:PdfDocumentViewer>

    </div>

    </form>

</body>

</html>

PDFViewer.aspx.cs

using System;

 

namespace WebApplication1

{

    public partial class WebForm2 : System.Web.UI.Page

    {

        protected void Page_Load(object sender, EventArgs e)

        {

            if (!IsPostBack)

            {

                this.PdfDocumentViewer1.CacheInterval = 1000;

                this.PdfDocumentViewer1.CacheTime = 1200;

                this.PdfDocumentViewer1.CacheNumberImage = 1000;

                this.PdfDocumentViewer1.ScrollInterval = 300;

                this.PdfDocumentViewer1.ZoomFactor = 1f;

                this.PdfDocumentViewer1.LoadFromFile("Upload/Test.pdf");

            }

        }

    }

}

Step 2

Now, if you can run the sample application, you can see how a PDF document viewer looks, as shown below:



How to implement the PDF file conversion using Spire.PDF library

We are going to discuss how to implement the PDF file conversion using Spire.PDF library with the sample application and show the demo in Asp.Net

Using PDF Convert into Doc file

Step 1

When you want to convert the Pdf file into the Doc file, you can add the following line:

PdfDocument pdfdocument = new PdfDocument();

string filepath = Server.MapPath("~/Upload/");

pdfdocument.LoadFromFile(filepath + "Test.pdf");

pdfdocument.SaveToFile(filepath + "TestDoc.doc", FileFormat.DOC);

System.Diagnostics.Process.Start(filepath + "TestDoc.doc");

If you want to convert other formats such as HTML, SVG, XPS and etc, you can change the file format as below screenshot



Step 2

Now, if you can run the sample application, you can see how a document file looks, as shown below:





Reference

Spire 

Conclusion

I hope you understood the Spire.PDF Installation, How to add Spire.PDFViewer component into VS Toolbox, How to add Spire package to project file, How to implement Spire.PDFViewer and Spire.PDF and so on. I have covered all the required things. If you found anything which I missed in this article, Please let me know. Please share your valuable feedback or comments and suggestion to improve the future articles

 


About the Author
Santhakumar Munuswamy is a seasoned Solution Architect and Most Valuable Professional in Cloud /AI solutions. He has been experienced around 14 years in Solution designing, Software Product Development, Technical Documentation, Project Management for Web and Cloud Applications. He has experience in the IT industry across different domains (Automotive, Telecommunications, Healthcare, Logistics & Warehouse Automation, etc.) with roles in Technical Architect, Genesys Consultant, Technical Lead, Team Lead, and Developer. He has experienced in mentorship and coaching high potential developers.

Follow Me: Facebook, Twitter, Google Plus, LinkedIn
blog comments powered by Disqus


Month List

Community Badges