Click here to Skip to main content
16,004,647 members

Comments by ManishSharma_dotnet (Top 1 by date)

ManishSharma_dotnet 5-Mar-14 7:24am View    
Download the dll of itextSharp.dll

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

private void btnExport_Click(object sender, EventArgs e)
{
Document doc = new Document(iTextSharp.text.PageSize.LETTER, 10, 10, 42, 35);
PdfWriter wri = PdfWriter.GetInstance(doc, new FileStream("d:\\Test.pdf", FileMode.Create));

doc.Open();//Open Document to write


Paragraph paragraph = new Paragraph("data Exported From DataGridview!");

//Create table by setting table value

Table t1 = new Table(2);
DataTable dt = (DataTable)dataGridView1.DataSource;

//Create Table Header

Cell cid = new Cell("ID");
Cell cname = new Cell("Name");

t1.AddCell(cid);
t1.AddCell(cname);

foreach (DataGridViewRow rows in dataGridView1.Rows)
{

string id = dataGridView1.Rows[rows.Index].Cells["empid"].Value.ToString();
string name = dataGridView1.Rows[rows.Index].Cells["ename"].Value.ToString();
//Create Cells
Cell c2 = new Cell(id);
Cell c1 = new Cell(name);
//Adding cells
t1.AddCell(c1);
t1.AddCell(c2);

}
doc.Add(paragraph);
doc.Add(t1);
doc.Close(); //Close document
//
MessageBox.Show("PDF Created!");
}