public WordDocument GetDocument(string htmlText) { WordDocument document = null; MemoryStream stream = new MemoryStream(); StreamWriter writer = new StreamWriter(stream, System.Text.Encoding.Default); htmlText = htmlText.Replace("\"", "'"); XmlConversion XmlText = new XmlConversion(htmlText); XhtmlConversion XhtmlText = new XhtmlConversion(XmlText); writer.Write(XhtmlText.ToString()); writer.Flush(); stream.Position = 0; document = new WordDocument(stream, FormatType.Html, XHTMLValidationType.None); return(document); }
public WordDocument GetDocument(string htmlText) { WordDocument document = null; MemoryStream stream = new MemoryStream(); StreamWriter writer = new StreamWriter(stream, System.Text.Encoding.Default); htmlText = htmlText.Replace("\"", "'"); var oldSrc = getArray(htmlText); // get the copy of the src attributes in img tag and store in an array XmlConversion XmlText = new XmlConversion(htmlText); XhtmlConversion XhtmlText = new XhtmlConversion(XmlText); var text = XhtmlText.ToString(); var newSrc = getArray(text); // get the modified src attributes for replacing and store in another array for (int i = 0; i < oldSrc.Count(); i++) // replace the modified src attributes with original { text = text.Replace(newSrc[i], oldSrc[i]); } writer.Write(text); writer.Flush(); stream.Position = 0; document = new WordDocument(stream, FormatType.Html, XHTMLValidationType.None); return(document); }