protected void btnPDF_Click(object sender, EventArgs e)
{
int columnsCount = GridView1.HeaderRow.Cells.Count;
PdfPTable pdfTable = new PdfPTable(columnsCount);
foreach (TableCell gridViewHeaderCell in GridView1.HeaderRow.Cells)
{
Font font = new Font();
font.Color = new BaseColor(GridView1.HeaderStyle.ForeColor);
PdfPCell pdfCell = new PdfPCell(new Phrase(gridViewHeaderCell.Text, font));
pdfCell.BackgroundColor = new BaseColor(GridView1.HeaderStyle.BackColor);
pdfTable.AddCell(pdfCell);
}
foreach (GridViewRow gridViewRow in GridView1.Rows)
{
if (gridViewRow.RowType == DataControlRowType.DataRow)
{
foreach (TableCell gridViewCell in gridViewRow.Cells)
{
Font font = new Font();
font.Color = new BaseColor(GridView1.RowStyle.ForeColor);
PdfPCell pdfCell = new PdfPCell(new Phrase(gridViewCell.Text, font));
pdfCell.BackgroundColor = new BaseColor(GridView1.RowStyle.BackColor);
pdfTable.AddCell(pdfCell);
}
}
}
Document pdfDocument = new Document(PageSize.A4, 5f, 10f, 15f, 12f);
PdfWriter.GetInstance(pdfDocument, Response.OutputStream);
pdfDocument.Open();
pdfDocument.Add(pdfTable);
pdfDocument.Close();
Response.ContentType = "application/pdf";
Response.AppendHeader("content-disposition", "attachment;filename=Rapor.pdf");
Response.Write(pdfDocument);
Response.Flush();
Response.End();
}
This my code . Yeah it is working but it have some design problem and not for 2 grid only for one grid.
Actually ı need 2 gridview in one pdf report and it must dont have desıgn problem.
Thank for helping and sorry for my bad english.
Screenshot is here;