问题
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> </td><td>ABCD</td><td> </td><td> </td><td> </td>
</tr><tr>
<th>test 2</th><td> </td><td>XYZ</td><td> </td><td> </td><td> </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