导出到PDF对齐问题

时间:2015-02-22 08:19:32

标签: c# asp.net pdf gridview itext

Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "attachment;filename=UserDetails.pdf");
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            StringWriter sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);
            grdUOM.AllowPaging = false;
            grdUOM.DataSource = (DataSet)(ViewState["pdf"]);
            grdUOM.DataBind();
            grdUOM.RenderControl(hw);
            grdUOM.HeaderRow.Style.Add("width", "15%");
            grdUOM.HeaderRow.Style.Add("font-size", "10px");
            grdUOM.Style.Add("text-decoration", "none");
            grdUOM.Style.Add("font-family", "Arial, Helvetica, sans-serif;");
            grdUOM.Style.Add("font-size", "8px");
            StringReader sr = new StringReader(sw.ToString());
            iTextSharp.text.Document pdfDoc = new iTextSharp.text.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();

以上是我将gridview导出为PDF的代码。Screen shot of the grid

Screen shot of the pdf

以上屏幕截图是gridview和PDF文件,后面是生成的。在PDF屏幕截图中,对齐完全失真。我必须在上面的代码中进行哪些更改才能在PDF文件中获得正确的表格格式?

0 个答案:

没有答案