iText For .Net Hello World

Like any new programming language or API, we all try to write a simple Hello World applicaion. Here is a simple console application that demonstrates how you can write a simple .Net application to write Hello World in a new PDF file.


static void Main(string[] args)
{
var doc = new iTextSharp.text.Document();
using (var fs = new FileStream("Hello.pdf", FileMode.OpenOrCreate))
{
PdfWriter writer = PdfWriter.GetInstance(doc, fs);
doc.Open();
doc.Add(new Paragraph("Hello ByteBlocks!"));
doc.AddAuthor("ByteBlocks.com");
doc.AddHeader("bbHeader", "iText For .Net");
doc.Close();
}
}

Very simple to use. Code opens a file stream for PDF where content is to be written. It then creates an instance of PdfWriter and opens it. Then it write a paragraph and sets author information... and DONE!

blog comments powered by Disqus

Smart Phones Poll

What smart phone do you currently own?





Show Results

Month List

Powered by BlogEngine.NET 2.0.0.49
Theme by Naveen Kohli