How to set the background color of a PDF document using iTextSharp

You can create a Rectangle object and set its BackgroundColor property. Use your Rectangle to initialize your Document.

Imports System
Imports System.IO

Imports iTextSharp.text
Imports iTextSharp.text.pdf

Public Class Chap0102

    Public Shared Sub Main()
        Console.WriteLine("Chapter 1 example 2: PageSize")

        ' step 1: creation of a document-object
        Dim pageSize As New Rectangle(144, 720)
        pageSize.BackgroundColor = New Color(&Hff, &Hff, &Hde) 
     '// pageSize.BackgroundColor.BackgroundColor = BaseColor.WHITE
        Dim document As New Document(pageSize)

        Try

            ' step 2:
            ' we create a writer that listens to the document
            ' and directs a PDF-stream to a file

            PdfWriter.getInstance(document, New FileStream("Chap0102.pdf", FileMode.Create))

            ' step 3: we open the document
            document.Open()

            ' step 4: we Add some paragraphs to the document
            For i As Integer = 0 To 4
                document.Add(New Paragraph("Hello World"))

            Next
        Catch de As DocumentException
            Console.[Error].WriteLine(de.Message)
        Catch ioe As IOException
            Console.[Error].WriteLine(ioe.Message)
        End Try

        ' step 5: we close the document
        document.Close()
    End Sub
End Class

Give it a try.

Call ASPX methods from the front end using PageMethods and not AJAX

In this article I will explain how to use and make call ASP.Net AJAX PageMethods using ASP.Net AJAX and ScriptManager.
ASP.Net AJAX ScriptManager allows you to call Server Side ASP.net methods from client side without any PostBack using PageMethods. Actually it is an AJAX call to the server but it allows us to call the method or function defined server side.
Enabling PageMethods
The first thing you need to do is add a ASP.Net AJAX ScriptManager to the page and set its EnablePageMethods property to true as shown below
<asp:ScriptManager ID=”ScriptManager1″ runat=”server” EnablePageMethods=”true”>
</asp:ScriptManager>

 

HTML Markup
<form id=”form1″ runat=”server”>
<asp:ScriptManager ID=”ScriptManager1″ runat=”server” EnablePageMethods=”true”>
</asp:ScriptManager>
<div>
Your Name :
<asp:TextBox ID=”txtUserName” runat=”server” ></asp:TextBox>
<input id=”btnGetTime” type=”button” value=”Show Current Time” onclick=”ShowCurrentTime()”/>
</div>
</form>

 

As you noticed above I have added a textbox when user can enter his name and a HTML button that calls a JavaScript method to get the Current Time.
Client Side Methods
<script type=”text/javascript”>
function ShowCurrentTime() {
PageMethods.GetCurrentTime(document.getElementById(<%=txtUserName.ClientID%>).value, OnSuccess);
}
function OnSuccess(response, userContext, methodName) {
alert(response);
}
</script>

 

Above the ShowCurrentTime method makes an AJAX call to the server using ASP.Net AJAX ScriptManager PageMethods and executes the GetCurrentTime method which accepts the username and returns a string value.
Server Side Methods
C#
[System.Web.Services.WebMethod]
public static string GetCurrentTime(string name)
{
return“Hello “ + name + Environment.NewLine + “The Current Time is: “
        + DateTime.Now.ToString();
}

 

VB.Net
<System.Web.Services.WebMethod()> _
Public Shared Function GetCurrentTime(ByVal name AsString) AsString
Return“Hello “& name & Environment.NewLine &“The Current Time is: “& _
            DateTime.Now.ToString()
EndFunction

 

The above method simply returns a greeting message to the user along with the current server time. An important thing to note is that the method is declared as static (C#) and Shared(VB.Net) and also it is declared as Web Method unless you do this you won’t be able to call the methods using ASP.Net ScriptManager PageMethods.

 

How To Install Yeoman Code Generators

Yeoman is a code generator tool that enables you to create simple software projects. Yeoman works by presenting you with a few questions in a wizard-like command line interface, and then uses your responses to generate the code files for your starter project.

In this article, you will learn how to install Yeoman and install the ASP.NET Core generators for Angular. Then, you will create an ASP.NET Core application with a C# back-end and an Angular Front End.

Continue reading “How To Install Yeoman Code Generators”

Read entire worksheet in an Excel workbook using VB.net

In the following section you can see How to find the last row data in Excel worksheet or How to find the Used area in a worksheet. For finding last row we are using WorkSheet.UsedRange . It will return the last cell . The follwoing code open an Excel file and read the entire content.

Continue reading “Read entire worksheet in an Excel workbook using VB.net”