How to Create Pdf File in Asp.Net Using Itextsharp

Itextsharp is a powerful tool that allows you to create pdf files from within your Asp.Net applications. In this article, we will see how we can use itextsharp to create pdf files. We will also see how we can add images and text to our pdf document.

  • Download and install the iTextSharp library
  • Add a reference to the iTextSharp library in your project
  • Create a new PDF document using the iTextSharp library
  • Add content to your PDF document using the iTextSharp library
  • Save your PDF document using the iTextSharp library

How to Generate Pdf Using Itextsharp in C#

Net I have seen many developers face this issue while working with ITextSharp. So, I decided to write a blog post on how to generate PDF using iTextSharp in ASP.NET C# .

Net. When we want to create PDF from HTML, the first thing that comes to our mind is iTextSharp. However, there are other ways as well to create PDF from HTML like using wkhtmltopdf or rotativa etc but still iTextSharp is most popular and widely used library for this purpose.

iTextSharp is a free and open source assembly that helps us to convert page output into PDF file. We can use it within ASP.NET web application or Windows Forms application. It’s very easy to use and has great documentation available online.

You can download the latest version of iTextSharp from NuGet Package Manager or manually adding reference into your project by downloading DLL file directly from In order to use iTextSharp, add its DLL reference into your web application or Windows Forms project and then write the code below: PdfWriter writer = PdfWriter.

; //Provide path where you want to generatePDF Document doc = new Document(PageSize., , , ); //Left, Right, Top, Bottom Margin doc.

.Open(); //Open Document to write data htmlparser parser = new htmlparser(writer); //New instance of HTMLWorker called with PdfWriter Instance parser.

.Parse(new StringReader(strContent)); //Call Parse method with string reader containing string value doc..Close(); Response…; //Response Object writer..CloseStream = false; //You need set this paramter true if you use Response Object MemoryStream ms = new MemoryStream(); writer..set_OutputStream(ms); //set output stream of writer as memorystream doc..Open(); // Open Documet again because we closed it earlier in response object parser..Parse(new StringReader(strContent)); //Again call Parse method but now parse srting reader which contains string value doc.


What is Itextsharp Text Pdf?

PDF is a file format that captures all the elements of a printed document as an electronic image that you can view, navigate, print, or forward to someone else. PDF files are created using Adobe Acrobat, Acrobat Capture, or similar products. iTextSharp is a free and open source library for manipulating PDF documents.

It allows you to add text, images, and signatures to existing PDF documents or create new ones from scratch.

How Do You Save Itextsharp Files?

When you want to save a document created with iTextSharp, you have two options. You can either save the document as a PDF file, or you can save it as an XML file. If you choose to save the document as a PDF file, you will need to use the PdfWriter class.

This class allows you to set various options for the PDF document, such as the title, subject, and keywords. Once you have set these options, you can call the PdfWriter.Write() method to save the document to a file. If you choose to save the document as an XML file, you will need to use the XmlWriter class.

This class allows you to create an XML version of your iTextSharp document. To do this, simply pass in the name of the XML file that you want to create when calling the XmlWriter constructor. Then call WriteStartDocument() and WriteEndDocument() methods surrounding all of your other code that adds content to the XML file.

What is Itextsharp in Asp Net?

iTextSharp is a C# port of iText, an open source Java library for PDF generation and manipulation. It can be used to create PDF documents from scratch, or to convert existing document formats such as Word or HTML into PDFs. iTextSharp is a popular tool for creating and manipulating PDF files in ASP.NET applications.

Can I Use Itextsharp for Free?

Yes, you can use iTextSharp for free. There is no charge to download and install the software, and there are no licensing fees. However, if you want to distribute your application commercially, you will need to purchase a commercial license.

C# How to create pdf file using itextSharp


If you need to generate a PDF file from your Asp.Net web application, you can use the iTextSharp library. This library allows you to create PDF files from scratch or convert existing HTML files into PDFs. In this article, we will show you how to use iTextSharp to create a PDF file in Asp.Net.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *