.net iTextSharp-将html文本放入单元格

.net iTextSharp-将html文本放入单元格,.net,vb.net,pdf,pdf-generation,itextsharp,.net,Vb.net,Pdf,Pdf Generation,Itextsharp,我需要创建一个报价PDF。 我想将带有HTML代码的文本写入表格单元格 ... Dim texto As String texto = Server.HtmlDecode("descripcion del producto<br />DESC") table.AddCell(AgregaCelda(doc, texto)) doc.Add(table) ... Private Shared Function AgregaCelda(ByVal doc As iTextShar

我需要创建一个报价PDF。 我想将带有HTML代码的文本写入表格单元格

...
 Dim texto As String
 texto = Server.HtmlDecode("descripcion del producto<br />DESC")
 table.AddCell(AgregaCelda(doc, texto))
 doc.Add(table)
...
Private Shared Function AgregaCelda(ByVal doc As iTextSharp.text.Document, ByVal Texto As   String) As iTextSharp.text.Cell
    Dim cell As iTextSharp.text.Cell = New iTextSharp.text.Cell(Texto)
    cell.Border = 0.0F
    Return cell
End Function
。。。
将文本变暗为字符串
texto=Server.HtmlDecode(“产品描述
DESC”) 表.AddCell(AgregaCelda(doc,texto)) 文件添加(表) ... 私有共享函数AgregaCelda(ByVal doc作为iTextSharp.text.Document,ByVal Texto作为字符串)作为iTextSharp.text.Cell 将单元格变暗为iTextSharp.text.cell=新的iTextSharp.text.cell(Texto) 单元格边框=0.0F 返回单元 端函数
尝试以下代码:

        table.AddCell("Some rich text:");
        PdfPCell cell = new PdfPCell();

        string htmlText =
            "<a class=\"unknownlink\" href=\".ashx\" title=\"\"></a><div class=\"imageleft\"></div><br><br><br><div style=\"font-size: 16px;\"><b>PDFsharp</b></div><b>A .NET library for processing PDF</b><br><br><br><b>PDFsharp</b> is the Open Source .NET library that easily creates and processes PDF documents on the fly from any .NET language. The same drawing routines can be used to create PDF documents, draw on the screen, or send output to any printer.<br>&nbsp;•&nbsp;<a class=\"pagelink\" href=\"Overview.ashx\" title=\"Overview\">Overview</a><br>&nbsp;•&nbsp;<a class=\"pagelink\" href=\"Features.ashx\" title=\"Features\">Features</a><br>&nbsp;•&nbsp;<a class=\"pagelink\" href=\"Downloads.ashx\" title=\"Downloads\">Downloads</a><br>&nbsp;•&nbsp;<a class=\"internallink\" href=\"/wiki/PDFsharpFirstSteps.ashx\" title=\"First Steps\">First Steps</a>  <small>'</small><br>&nbsp;•&nbsp;<a class=\"internallink\" href=\"/wiki/PDFsharpArticles.ashx\" title=\"Articles\">Articles</a>  <small>'</small><br>&nbsp;•&nbsp;<a class=\"internallink\" href=\"/wiki/PDFsharpSamples.ashx\" title=\"Samples\">Samples</a> <small>'</small><br>&nbsp;•&nbsp;<a class=\"internallink\" href=\"/wiki/PDFsharpFAQ.ashx\" title=\"FAQs\">FAQs</a>  <small>'</small><br>&nbsp;•&nbsp;<a class=\"internallink\" href=\"/wiki/\" title=\"Wiki\">Wiki</a>  <small>'</small><br>";
        using (StringReader sr = new StringReader(htmlText))
        {
            List<IElement> elements = iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList(sr, null);
            foreach (IElement e in elements)
            {
                //Add those elements to the paragraph
                cell.AddElement(e);
            }
        }

        table.AddCell(cell);
table.AddCell(“一些富文本:”);
PdfPCell cell=新的PdfPCell();
字符串htmlText=
“


用于处理PDF的PDFsharpA.NET库


PDFsharp是一个开源的.NET库,可以轻松地从任何.NET语言动态创建和处理PDF文档。相同的绘图例程可用于创建PDF文档、在屏幕上绘图或将输出发送到任何打印机。




•”
•“
•”
•“
•”
•“; 使用(StringReader sr=新的StringReader(htmlText)) { List elements=iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList(sr,null); foreach(元素中的元素e) { //将这些内容添加到该段中 单元。附加元素(e); } } 表2.AddCell(cell);
您遇到了什么问题?HTML是否显示为文本而未被呈现?是的,Chris,它显示的内容类似于
…某些文本…
  • 。。。类似这样的东西,我需要以HTML.PDF格式呈现,HTML是100%不相关的。不过,iTextSharp有一个名为XmlWorker的助手库,在某种程度上,它可以将一些HTML标记转换为PDF命令。感谢您的回答,我尝试使用HTMLWORKER将文本解析为PDF,但我不知道如何控制它显示在表格单元格中。对不起,我的英语不是很好。Dim hw作为新的iTextSharp.text.html.simpleparser.HTMLWorker(doc)hw.Parse(New StringReader(texto))HTMLWorker是旧的,不再维护。它支持非常简单的HTML,基本上是粗体、斜体和简单的字体信息。XmlWorker是完成所有当前工作的地方。如果你搜索这个网站,你会发现这两个例子很多。如果你只有像

    这样简单的东西,你可以(也应该)使用iTextSharp。否则,请尝试一个解析器,让我们知道您遇到了什么问题。