Saturday, December 26, 2009

Creating PDF file using ASP.NET,C#

This is an interesting thing to accomplish creating PDF file in ASP.NET ,C#. Let me share with you the techniques of creating PDF. Here are the following steps.
step-1: download the following itextsharp .dll from the following link
step-2: Add reference to the .dll in your project using Visual studio
step-3: Now use the following code only to create a simple paragraph in .pdf file.
//creating pdf source code
try {
Document mydoc = new Document(PageSize.A4.Rotate());
PdfWriter.GetInstance(mydoc,new FileStream("masud.pdf",FileMode.Create));
mydoc.Open();
mydoc.Add(new Paragraph("This is the first paragraph written by me"));
mydoc.Close();
MessageBox.Show("PDF created successfully!");

}
catch (Exception exc)
{
MessageBox.Show("Failed to create PDF file"+exc.Message);
}

This is how you can create PDF uisng some dll. So interesting!

thanks. Masud (26-12-2009)

No comments:

Post a Comment