我的页面中有 11 个网格视图我想将它导出到单个 pdf 文件中,我搜索了这个查询并实现了我得到的代码,但它没有工作并生成带有黑色背景的 pdf,只有标题不显示内容。请提供将所有 10 个网格视图导出到单个 pd 的代码
protected void btnExportToPDF_Click(object sender, EventArgs e)
{
GridView[] gvpdf = new GridView[] { GV1,GV2,GV3,GV4,GV5,GV6,GV7,GV8,GV9,GV10,GV11};
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 10f);
MemoryStream ms = new MemoryStream();
PdfWriter.GetInstance(pdfDoc, ms);
pdfDoc.Open();
for (int i = 0; i < gvpdf.Length; i++)
{
if (gvpdf[i].Visible)
{
PdfPTable pdfTbl = new PdfPTable(gvpdf[i].HeaderRow.Cells.Count);
pdfTbl.SpacingAfter = 20f;
foreach (TableCell headerTblCell in gvpdf[i].HeaderRow.Cells)
{
System.Drawing.Font font = new System.Drawing.Font("Arial", 24, FontStyle.Bold);
font.Color = new BaseColor(gvpdf[i].HeaderStyle.ForeColor);
PdfPCell pdfCell = new PdfPCell(new Phrase(headerTblCell.Text));
pdfCell.BackgroundColor = new BaseColor(gvpdf[i].HeaderStyle.ForeColor);
pdfTbl.AddCell(pdfCell);
}
foreach (GridViewRow gvRow in gvpdf[i].Rows)
{
foreach (TableCell tblCell in gvRow.Cells)
{
System.Drawing.Font font = new System.Drawing.Font("Arial", 24, FontStyle.Bold);
font.Color = new BaseColor(gvpdf[i].RowStyle.ForeColor);
PdfPCell pdfCell = new PdfPCell(new Phrase(tblCell.Text));
pdfCell.BackgroundColor = new BaseColor(gvpdf[i].RowStyle.ForeColor);
pdfTbl.AddCell(pdfCell);
}
}
pdfDoc.Add(pdfTbl);
}
}
pdfDoc.Close();
byte[] content = ms.ToArray();
Response.ContentType = "application/pdf";
Response.AppendHeader("content-disposition", "attachment;filename=report_" + ".pdf");
Response.BinaryWrite(content);
Response.Flush();
Response.End();
}