private void AssignEventHandlers()
{
this.btnLocation.Click += new EventHandler(OnBrowse);
this.btnExport.Click += new EventHandler(OnExport);
}
private void OnExport(object sender, EventArgs e)
{
Document document = new Document();
document.AddTitle("Test PDF Creator");
using (FileStream stream = new FileStream(Path.Combine(this.txtFilePath.Text, "Example.pdf"), FileMode.Create, FileAccess.Write))
{
PdfWriter writer = PdfWriter.GetInstance(document, stream);
document.Open();
PdfPTable table = new PdfPTable(3);
PdfPRow rowItem = null;
PdfPCell[] cell = null;
Phrase phrase = null;
foreach (ListViewItem listItem in this.lvTest.Items)
{
cell = new PdfPCell[3];
phrase = new Phrase(listItem.Text);
cell[0] = new PdfPCell();
cell[0].AddElement(phrase);
phrase = new Phrase(listItem.SubItems[1].Text);
cell[1] = new PdfPCell();
cell[1].AddElement(phrase);
phrase = new Phrase(listItem.SubItems[2].Text);
cell[2] = new PdfPCell();
cell[2].AddElement(phrase);
rowItem = new PdfPRow(cell);
table.Rows.Add(rowItem);
}
document.Add(table);
document.Close();
}
}