fine here full code..
1st step : Assign DATAGRIDVIEW TABLE TO DATATABLE OBJECT DT..
After that change column names in follwing code..
string filename="TEST.PDF";
Document document = new Document(new Rectangle(288f, 144f), 10, 10, 10, 10);
document.SetPageSize(iTextSharp.text.PageSize.A4.Rotate());
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(filename, FileMode.Create));
iTextSharp.text.Font font5 = iTextSharp.text.FontFactory.GetFont(FontFactory.HELVETICA, 11);
document.Open();
PdfPTable table = new PdfPTable(dt.Columns.Count-2);
PdfPRow row = null;
float[] widths = new float[] { 4f, 4f,4f,4f,4f,4f,4f };
table.SetWidths(widths);
table.WidthPercentage = 100;
cell1.Colspan = dt.Columns.Count;
cell1.Padding = 5;
table.AddCell(cell1);
PdfPCell cell;
Font ColFont = FontFactory.GetFont(FontFactory.HELVETICA, 15, Font.BOLD);
Chunk chunkCols = new Chunk("Candidate's Interview List", ColFont);
cell = new PdfPCell(new Paragraph(chunkCols));
cell.Colspan = dt.Columns.Count;
cell.Padding = 5;
table.AddCell(cell);
PdfPCell cellH;
Font ColFont3 = FontFactory.GetFont(FontFactory.HELVETICA, 12, Font.BOLD);
Chunk chunkCols1 = new Chunk("Report From : " + (startdate == "01/01/0001" ? "-" : startdate) + " To : " + (enddate == "12/31/9999" ? "-" : enddate), ColFont3);
cellH = new PdfPCell(new Paragraph(chunkCols1));
cellH.Colspan = dt.Columns.Count;
cellH.Padding = 5;
table.AddCell(cellH);
foreach (DataColumn c in dt.Columns)
{
if (c.ColumnName != "Recruiter Name" && c.ColumnName != "Type")
{
cell = new PdfPCell(new Paragraph(new Chunk(c.Caption, FontFactory.GetFont(FontFactory.HELVETICA, 11, Font.BOLD))));
table.AddCell(cell);
}
}
table.HeaderRows = 4;
table.DefaultCell.BorderWidth = 1;
DataTable uniqueCols = dt.DefaultView.ToTable(true, "Recruiter Name");
Font ColFont1 = FontFactory.GetFont(FontFactory.HELVETICA, 12, Font.BOLD);
if (uniqueCols.Rows.Count > 0)
{
for (int distRN = 0; distRN < uniqueCols.Rows.Count; distRN++)
{
string RecruiterName = uniqueCols.Rows[distRN]["Recruiter Name"].ToString();
if (RecruiterName != "Not Available")
{
DataRow[] dtDetails = dt.Select("[Recruiter Name] = '" + RecruiterName.Replace("'", "''") + "'");
Chunk chunkCols2 = new Chunk("Account Manager : " + RecruiterName, ColFont1);
cell = new PdfPCell(new Paragraph(chunkCols2));
cell.Colspan = dt.Columns.Count - 2;
cell.Padding = 5;
cell.MinimumHeight = 25f;
cell.Border = 0;
table.AddCell(cell);
foreach (DataRow r in dtDetails)
{
PdfPCell DateInterview = new PdfPCell(new Paragraph(r["Date of Interview"].ToString(), font5));
DateInterview.HorizontalAlignment = Element.ALIGN_LEFT;
table.AddCell(DateInterview);
PdfPCell CCandName = new PdfPCell(new Paragraph(r["Candidate Name"].ToString(), font5));
CCandName.HorizontalAlignment = Element.ALIGN_LEFT;
table.AddCell(CCandName);
PdfPCell CCompnyName = new PdfPCell(new Paragraph(r["Company Name"].ToString(), font5));
CCompnyName.HorizontalAlignment = Element.ALIGN_LEFT;
table.AddCell(CCompnyName);
PdfPCell CCompnyClintName = new PdfPCell(new Paragraph(r["Company Contact Name"].ToString(), font5));
CCompnyClintName.HorizontalAlignment = Element.ALIGN_LEFT;
table.AddCell(CCompnyClintName);
PdfPCell CTitle = new PdfPCell(new Paragraph(r["Title"].ToString(), font5));
CTitle.HorizontalAlignment = Element.ALIGN_LEFT;
table.AddCell(CTitle);
PdfPCell CSubject = new PdfPCell(new Paragraph(r["Subject"].ToString(), font5));
CSubject.HorizontalAlignment = Element.ALIGN_LEFT;
table.AddCell(CSubject);
PdfPCell DateAdded = new PdfPCell(new Paragraph(r["Date Added"].ToString(), font5));
DateAdded.HorizontalAlignment = Element.ALIGN_LEFT;
table.AddCell(DateAdded);
}
}
}
}
document.Add(table);
Paragraph footer = new Paragraph("COMANY NAME", FontFactory.GetFont(FontFactory.TIMES, 10, iTextSharp.text.Font.NORMAL));
footer.Alignment = Element.ALIGN_RIGHT;
PdfPTable footerTbl = new PdfPTable(1);
footerTbl.TotalWidth=1000;
footerTbl.HorizontalAlignment = Element.ALIGN_CENTER;
PdfPCell cell2 = new PdfPCell(footer);
cell2.Border = 0;
cell2.PaddingLeft = 10;
footerTbl.AddCell(cell2);
footerTbl.WriteSelectedRows(0, -1, 550, 30, writer.DirectContent);
document.Close();