Writing content of HTML table into PDF doc using iTextSharp in asp.net

こ雲淡風輕ζ 提交于 2019-12-23 05:17:09

问题


I have an HTML table stored in a string. I want to write that string into a PDF document using iTextSharp library. Please suggest the approach. Below is the table I want to write in a PDF file

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

回答1:


Its is possible. try this.

    //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();
    }


来源:https://stackoverflow.com/questions/17776251/writing-content-of-html-table-into-pdf-doc-using-itextsharp-in-asp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!