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(); }
pdfDocument.Add(pdfTable1); pdfDocument.Add(pdfTable2);
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)