我已经使用 iTextSharp 从 gridview 导出到 PDF。由于 gridview 列更多,因此 PDF 中的列未对齐并且非常小。我尝试在代码隐藏和 .aspx 页面中编写样式。但大小没有变化。
.aspx 页面
<asp:GridView ID="grdResult" runat="server" AutoGenerateColumns="true" Width="100%"
CellPadding="3" CellSpacing="3" Font-Size="10pt">
<HeaderStyle Font-Bold="true" Width="250px" />
</asp:GridView>
.cs 页面
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=MARGEmployees.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
HtmlForm frm = new HtmlForm();
grdResult.Parent.Controls.Add(frm);
frm.Attributes["runat"] = "server";
frm.Controls.Add(grdResult);
frm.RenderControl(hw);
grdResult.HeaderRow.Style.Add("width", "15%");
grdResult.HeaderRow.Style.Add("font-size", "10px");
grdResult.Style.Add("font-family", "Tahoma");
grdResult.Style.Add("font-size", "8px");
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A4, 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();
请帮助我