繁体   English   中英

iTextSharp-将HTML文本插入单元格

[英]iTextSharp - html text into cell

我需要创建一个报价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

试试这个代码:

        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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM