解析Tinymce编辑器字符串时出错

时间:2016-01-07 11:51:30

标签: c# itextsharp

我正在使用以下代码解析HTML。 html来自tinymce编辑器。我刚刚缩短了我的代码。 EmailBody string中可以有任意数量的图像,因为用户在tinymce编辑器中选择了这些图像。

除非电子邮件正文中有<img src="">标记,否则一切正常。

我在此行htmlWorker.Parse(sr);

上收到错误
string EmailBody = @"<p><img src=""http://weknowyourdreams.com/images/smile/smile-07.jpg""></p>";
using (var ms = new MemoryStream())
{
    //Create an iTextSharp Document which is an abstraction of a PDF but **NOT** a PDF
    using (var doc = new Document())
    {
        //Create a writer that's bound to our PDF abstraction and our stream
        using (var writer = PdfWriter.GetInstance(doc, ms))
        {
            //Open the document for writing
            doc.Open();
            using (var htmlWorker = new iTextSharp.text.html.simpleparser.HTMLWorker(doc))
            {
                //HTMLWorker doesn't read a string directly but instead needs a TextReader (which StringReader subclasses)
                using (var sr = new StringReader(EmailBody))
                {
                    //Parse the HTML
                    htmlWorker.Parse(sr);
                }
            }
            doc.Close();
        }
    }
    bytes = ms.ToArray();
}

给我这个错误:

  

无法访问已关闭的流

如何解决此错误?

0 个答案:

没有答案