RubyPDF Blog .NET,English,iText in Action,iTextSharp(iText#),PDF HelloWorld–C# version examples of iText in Action

HelloWorld–C# version examples of iText in Action

Create a PDF in Five steps

using System;
using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;

namespace chapter01
	/// this example ported by Steven Lee 
	/// This example of java version was written by Bruno Lowagie.
	/// It is part of the book 'iText in Action' by Manning Publications.
	/// ISBN: 1932394796
	/// This example generates a simple 'Hello World' PDF file.
	public class HelloWorld
		/// Generates a PDF file with the text 'Hello World'
		public static void Main() 
			System.Console.WriteLine("Chapter 1: example HelloWorld");
			System.Console.WriteLine("-> Creates a PDF file with the text 'Hello World';");
			System.Console.WriteLine("   Default values are used for PageSize and margins.");
			System.Console.WriteLine("-> jars needed: iText.jar");
			System.Console.WriteLine("-> files generated in /results subdirectory:");
			System.Console.WriteLine("   HelloWorld.pdf");
			// step 1: creation of a document-object
			Document document = new Document();
				// step 2:
				// we create a writer
					// that listens to the document
					// and directs a PDF-stream to a file
					new FileStream("HelloWorld.pdf",FileMode.Create));
				// step 3: we open the document
				// step 4: we add a paragraph to the document
				document.Add(new Paragraph("Hello World"));
			catch (DocumentException de) 
			catch (IOException ioe) 

			// step 5: we close the document

the java version can be found at:
or from the book of iText in Action

3 thoughts on “HelloWorld–C# version examples of iText in Action”

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.