2012-08-23 25 views
0

我试图在我的网页中使用itextsharp将包含数据的面板包含在标签和GridView中。但是,如果我不能将样式应用到GridView。使用itextsharp在PDF GridView中应用样式

你能帮我吗?

我使用css和html样式来设计我的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(); 

如何在面板中添加样式到Gridview?

面板ID是pnl_print

GridView控件ID是GV1

你能帮助我吗?

回答

0

我不确定是否可以使用itextsharp为pdf添加额外的css,但是您可以始终使用itextsharp使用类似这样的函数创建css,并在itextsharp css类中重写样式。

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

我正在制作一个面板到PDF,面板包含GridView我只参照itextsharp中的面板。所以GridView是面板的子元素。如何在面板中添加样式到GridView –

+0

是的,但是您正在使用itextsharp将面板添加到pdf,对吗?你需要使用上面的例子来添加样式到你用itextsharp创建的任何元素 –

+0

你能详细解释一下吗,我是这个主题的新手,我已经添加了我的代码。 –