Aspose.Pdf

Set License for Web User Control

It's very common to use the Aspose.Pdf license with Windows or Web based .NET applications. All of our customers know that how to use (or embed) the license with their applications. But, there is a bit difference when it comes about Web User Controls.

 

If you are going to create a Web User Control using any .NET based language then the page parameter in SetLicense method of the Pdf class should be the reference of the page of the control. The example below shows how to set license in web user control.

 

Example:

 

[C#]

 

 

public abstract class WebUserControl1 : System.Web.UI.UserControl

{

   protected System.Web.UI.WebControls.Button Button1;

 

 

   private void Page_Load(object sender, System.EventArgs e)

   {

   }

 

 

   #region Web Form Designer generated code

   //...

   #endregion

 

 

   private void Generate(object sender, System.EventArgs e)

   {

         //Instantiating Pdf instance

        Pdf p = new Pdf();

 

 

        //Set license and the reference of the page that would contain

        //the Web User Control

        Pdf.SetLicense(@"e:\projects\CSharp\customer\Aspose.Pdf.lic",this.Page);

 

 

        //Create a section and then add a text paragraph to the section

        Section sec = p.Sections.Add();

        sec.Paragraphs.Add(new Text("Hello world"));

 

 

        //Save the Pdf to the response object

        p.Save(Response);

 

 

        //Close the response

        Response.End();

   }

}

 

 

[VB.NET]

 

 

Public MustInherit Class WebUserControl1

   Inherits System.Web.UI.UserControl

     Protected WithEvents Button1 As System.Web.UI.WebControls.Button

 

 

        #Region " Web Form Designer Generated Code "

        '...

        #End Region

 

 

        Private Sub Page_Load(ByVal sender As System.Object,

                        ByVal e As System.EventArgs) Handles MyBase.Load

        End Sub

 

 

        Private Sub Generate(ByVal sender As System.Object,

                        ByVal e As System.EventArgs) Handles Button1.Click

 

 

           'Instantiating Pdf instance

           Dim p As Pdf = New Pdf()

 

 

           'Set license and the reference of the page that would contain

           'the Web User Control

           Pdf.SetLicense("e:\projects\CSharp\customer\Aspose.Pdf.lic", Me.Page)

 

 

           'Create a section and then add a text paragraph to the section       

           Dim sec As Section = p.Sections.Add()

           sec.Paragraphs.Add(New Text("Hello world"))

 

 

           'Save the Pdf to the response object               

           p.Save(Response)

 

 

           'Close the response

           Response.End()

        End Sub

End Class