0

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>
SharpCoder
  • 17,049
  • 41
  • 140
  • 238

1 Answers1

4

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();
    }
Manish Sharma
  • 2,388
  • 2
  • 15
  • 30