2012-08-23 24 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

你能詳細解釋一下嗎,我是這個主題的新手,我已經添加了我的代碼。 –