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!