I am having a bizarre issue trying to convert an HTML string to a PDF. I have tried several example for the internet and all are given me this same error on the htmlparser.Parse() method.
Here is the code:
Byte[] bytes;
StringReader sr = new StringReader(sbEmail.ToString());
var pdfDoc = new itxt.Document(itxt.PageSize.LETTER_LANDSCAPE, 15, 15, 0, 0);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
using (MemoryStream memoryStream = new MemoryStream())
{
PdfWriter writer = PdfWriter.GetInstance(pdfDoc, memoryStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
bytes = memoryStream.ToArray();
memoryStream.Close();
}
There is no physical file path involved yet. So how can there be a problem with a file path?
Maybe this, can help you: https://stackoverflow.com/a/12181998/9492698
It's about HTMLWorker is deprecated and you can use XMLWorker instead. See here for more advanced usage of XMLWorker: info