【问题标题】:Applying Styles in PDF GridView using itextsharp使用 itextsharp 在 PDF GridView 中应用样式
【发布时间】:2012-08-18 14:20:27
【问题描述】:

我正在尝试在我的网页中使用 itextsharp 将包含标签和 GridView 等数据的面板打印到 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();

如何在 Panel 中向 Gridview 添加样式??

面板 ID 是 pnl_print

GridView ID 为 gv1

你能帮帮我吗?

【问题讨论】:

    标签: c# asp.net .net pdf-generation itextsharp


    【解决方案1】:

    我不确定是否可以使用 itextsharp 将外部 css 添加到 pdf,但您始终可以使用类似的东西创建一个带有 itextsharp 提供的功能的 css,重写 itextsharp css 类中的样式。

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

    【讨论】:

    • 我在 PDF 中制作了一个面板,并且该面板包含 GridView 我只引用了 itextsharp 中的面板。所以 GridView 是面板的子元素。如何在 Panel 中为 GridView 添加样式
    • 是的,但是您正在使用 itextsharp 将面板添加到 pdf,对吗?您需要使用上面的示例为您使用 itextsharp 创建的任何元素添加样式
    • 你能详细解释一下吗,我是这个主题的新手,我已经添加了我的代码。
    猜你喜欢
    • 2013-08-10
    • 2013-09-02
    • 2019-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-21
    相关资源
    最近更新 更多