0

我有一个存储在字符串中的 HTML 表。我想使用 iTextSharp 库将该字符串写入 PDF 文档。请提出方法。下面是我想写成 PDF 文件的表格

<table>
<tr>
        <th>test</th><td>&nbsp;&nbsp;</td><td>ABCD</td><td>&nbsp;&nbsp;</td><td>&nbsp;&nbsp;</td><td>&nbsp;&nbsp;</td>
    </tr><tr>
        <th>test 2</th><td>&nbsp;&nbsp;</td><td>XYZ</td><td>&nbsp;&nbsp;</td><td>&nbsp;&nbsp;</td><td>&nbsp;&nbsp;</td>
    </tr>
</table>
4

1 回答 1

4

它是可能的。尝试这个。

    //HTMLString = Pass your Html , fileLocation = File Store Location
    public void converttopdf(string HTMLString, string fileLocation)
    {
        Document document = new Document();

        PdfWriter.GetInstance(document, new FileStream(fileLocation, FileMode.Create));
        document.Open();

        List<IElement> htmlarraylist = HTMLWorker.ParseToList(new StringReader(HTMLString), null);
        for (int k = 0; k < htmlarraylist.Count; k++)
        {
            document.Add((IElement)htmlarraylist[k]);
        }

        document.Close();
    }
于 2013-07-22T04:35:24.320 回答