Applying Styles in PDF GridView using itextsharp

假装没事ソ 提交于 2019-12-11 16:24:03

问题


I'm trying to print a panel which contains data like labels and GridView to a PDF using itextsharp in my webpage. But if i'm not able to apply the styles to the GridView.

Can you help me??

I'm using both css and html styles to style my GridView.

Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "inline;filename=" + filename + ".pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
pnl_print.RenderControl(hw);

StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();

sr.Close();
hw.Close();
sw.Close();

How can I add styles to Gridview in Panel??

Panel ID is pnl_print

GridView ID is gv1

Can you Help me out ??


回答1:


I am not sure if it possible to add an extranal css to the pdf with itextsharp, but you can always create a css with a functions frovided by itextsharp using something like this, rewriting the style in the itextsharp css class.

StyleSheet styles = new StyleSheet();
styles.LoadTagStyle("p", "size", "10pt");
styles.LoadTagStyle("p", "color", "#0000ff");     


来源:https://stackoverflow.com/questions/12085337/applying-styles-in-pdf-gridview-using-itextsharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!