Monday, December 24, 2007

iTextSharp

Today, I got the work to create the PDF document from ASP.net application. Using google I have searched any components which are available for free download. At that time, I got this component, iTextSharp, from Souceforge.net. Initially it is developed in Java with the name of iText.

We can get the latest version of this component at http://sourceforge.net/projects/itextsharp/. In this link they provide the example code also. This component is very useful and easy to use for ASP.net developers.

Sample code

// step 1: creation of a document-object
Document document = new Document();
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(@"C:\temp\Chap0101.pdf" , FileMode.Create));
// step 3: we open the document
document.Open();
// step 4: we Add a paragraph to the document
document.Add(new Paragraph( "Hello World"));
}
catch (DocumentException de)
{
Console.Error.WriteLine(de.Message);
}
catch ( IOException ioe)
{
Console.Error.WriteLine(ioe.Message);
}

// step 5: we close the document
document.Close();

Some Article Links

iTextSharp(iText#) example in asp.net - http://blog.rubypdf.com/2006/10/25/itextsharpitext-example-in-aspnet/
How to generate Arabic PDF files - http://www.developerfusion.co.uk/forums/p/40095/146877/

0 comments: