我已经使用iTextSharp从gridview导出到PDF.由于gridview列更多,因此PDF中的列未对齐且非常小.我尝试在codebehind和.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,0f); HTMLWorker htmlparser = new HTMLWorker(pdfDoc); PdfWriter.GetInstance(pdfDoc,Response.OutputStream); pdfDoc.open(); htmlparser.Parse(sr); pdfDoc.Close(); Response.Write(pdfDoc); Response.End();
请帮帮我