Hi,
I am using RTE control and have this behavior: I copy some text from word document and paste it to the RTE then, i want to export to pdf but an error ocurrs in server side in the 'GetDocument' method. In the attached file there is an image with the error mesagge. Also, there is a .txt document with the content of the "htmlText" variable that the GetDocument method receives.
My server side code:
[System.Web.Mvc.ValidateInput(false)]
[Route("api/RTE/ExportToPDF")]
[HttpPost]
public void ExportToPDF()
{
string RTEID = HttpContext.Current.Request.QueryString["rteid"];
string FileName = HttpContext.Current.Request.Params[RTEID + "_inputFile"];
string htmlText = HttpContext.Current.Request.Params[RTEID + "_inputVal"];
WordDocument document = GetDocument(htmlText);
DocToPDFConverter converter = new DocToPDFConverter();
PdfDocument pdfDocument = converter.ConvertToPDF(document);
pdfDocument.Save(FileName + ".pdf", HttpContext.Current.Response, HttpReadType.Save);
}
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;
}
Attachment:
RTEFiles_4e43445c.zip