How to Create a PDF Using iTextSharp

Written by jim campbell
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Create a PDF Using iTextSharp
Create PDF documents with iTextSharp. (document image by AGphotographer from

iTextSharp provides ASP.NET and Java developers the ability to create and edit PDF files. PDF files are standard documents readable with the Adobe Reader software. PDF files are commonly used to distribute documents that aren't editable, and they provide website readers with a standard layout for reading important files such as contracts, white papers and manuals. The iTextSharp object is free to download and easily integrates with your web projects.

Skill level:

Other People Are Reading


  1. 1

    Insert the iTextSharp library at the top of your code file. The "using" keyword includes libraries in your source code. Place the following code at the top of your code file:

    using iTextSharp.text; using iTextSharp.text.pdf;

  2. 2

    Create a document object. This document object holds the dimensions for the PDF file. The following code creates the document and sets its dimensions:

    Document pdfdoc = new Document(); Document pdfdoc = new Document(PageSize.LETTER);

  3. 3

    Create the file on the web server hard drive. The file name can be any name you want for the PDF. The following code demonstrates how to create the PDF:

    PdfWriter.GetInstance(pdfdoc, new FileStream("newpdf.pdf", FileMode.Create));

  4. 4

    Open the new document and write text to it. You can write several lines of text to the PDF before closing it. In this example, a simple "Hello World" is written by using following code:

    pdfdoc.Open(); pdfdoc.Add("Hello World.");

  5. 5

    Close the PDF document. After you have written all your text to the file, the "Close()" function is required. This releases the PDF file from memory. The following code closes your file:


Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.