Export to pdf document does not work when copy text from word document

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

3 Replies

KV Karthikeyan Viswanathan Syncfusion Team September 9, 2018 06:37 AM UTC

Hi Juan, 
 
Thanks for contacting Syncfusion support. 
 
We have checked the provided content in the text file. It contains invalid attributes in the HTML element. These usually occur when content is copied from the word file. The DocIO’s HTML to Word conversion works only when the HTML content is a valid XHTML format.  

So, when pasting the content from the word, we suggest you to enable pasteCleanupSettings to clean unwanted attributes and elements from the copied content that are not supported in HTML. Kindly refer to the following UG link: https://help.syncfusion.com/js/richtexteditor/clean-elements 

Also we can perform client side XHTML validation by setting enableXHTML to true. Kindly refer to the following UG link: https://help.syncfusion.com/js/richtexteditor/xhtml-validation 

Once the content is proper XHTML format, it will be converted to PDF document. 
 
Regards, 
Karthikeyan V. 



JJ Juan Jose Uribe September 11, 2018 02:46 PM UTC

Thnaks for your help, it is working now.

Regards,

Juan J. Uribe


KV Karthikeyan Viswanathan Syncfusion Team September 12, 2018 04:24 AM UTC

Hi Juan,  
 
Thanks for the update. 
 
We are glad to hear that your issue has been resolved. 
 
Regards, 
Karthikeyan V. 


Loader.
Up arrow icon