【发布时间】:2014-08-12 21:17:19
【问题描述】:
我正在将 gridview 导出为 pdf。一切正常,但是,当生成 PDF 时,背景为白色,标题字体颜色为灰色。真的很难看。我正在尝试在导出之前将标题前景色更改为黑色。它不工作。
有什么建议吗?
public void ExportToPDF()
{
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=CallDetail.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
GridView1.AllowPaging = false;
this.GetData();
GridView1.RenderControl(hw);
HtmlForm frm = new HtmlForm();
frm.Attributes["runat"] = "server";
GridView1.HeaderRow.Style.Add("width", "15%");
GridView1.HeaderRow.Style.Add("font-size", "10px");
GridView1.Style.Add("text-decoration", "none");
GridView1.Style.Add("font-family", "Arial, Helvetica, sans-serif;");
GridView1.Style.Add("font-size", "26px");
for (int col = 0; col < GridView1.HeaderRow.Controls.Count; col++)
{
TableCell tc = GridView1.HeaderRow.Cells[col];
tc.Style.Add("color", "#FFFFFF");
tc.Style.Add("background-color", "#444");
}
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A2, 7f, 7f, 7f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();
}
UPDATE*** 添加了更新的代码和屏幕截图。
【问题讨论】:
标签: c# asp.net pdf gridview colors