Quote: First of all, download the DLL file (itextsharp). You can download it from here. Then open a new project in ASP.NET where language is C# .NET. Right click on the project name and select "Add Reference". Then browse the DLL file. Now go to your .aspx page and drag a label or textbox and a button. Our aim is, there will be some text in the label or textbox and when we click the button, it will create a PDF file having the text in it. Here, I am using a
Label for HTML format and my label name is
lblArticle. And I have created a folder in my project named pdf.
Now go to your .cs page, add the namespace, and copy the following code:
Then go to your button click event and copy the following code:
Document document = new Document();
PdfWriter.GetInstance(document, new FileStream(Server.MapPath("~/") + "pdf/" + "print.pdf", FileMode.Create));
List<ielement> htmlarraylist = iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList(
new StringReader(lblArticle.Text), null);
for (int k = 0; k < htmlarraylist.Count; k++)
Paragraph mypara = new Paragraph();
catch (Exception ex)
lblArticle.Text = ex.Message;
I have been working in .Net platform over 4 years, I am expert in both Desktop and Web Application. I used both C# and VB for my code. I love to face challenge in coding, because I always believe that "Failure doesn't kill you... it increases your desire to make something happen.