Import HTML file issue

4 posts, 0 answers
  1. Daniel
    Daniel avatar
    2 posts
    Member since:
    Apr 2011

    Posted 15 Apr 2011 Link to this post

    Hi,

    i have a issue converting a docx file into a HTML file and then displayig the HTML in the RichTexBox control.
    I am trying to upload a docx file with a table in it, by convertig the byte array into a RadDocument with the DocxFromatProvider.
    This works great. Then i export the RadDocument into a HMTL string with the HtmlFormatProvider. This also works.
    Then i try to create a new RadDocument with the generated HTML string and the HtmlFormatProvider. But it throws me a InvalidCastException. Here is my code:

                        data = dlg.File.OpenRead();
                        RadDocument tmpDoc = new DocxFormatProvider().Import(data);
                        
                        html = new HtmlFormatProvider().Export(tmpDoc);
                        Document = new HtmlFormatProvider().Import(html);

    The last line causes the exception. The HTML in the string is valid html.
    It seems that a docx containing a table can be converted in valid HTML, but it cannot been imported as RadDocument.
    When i try to upload the generated html in your silverlight demo RichTextBox it says "The file cannot be opened".

    Is there any solution for this issue?
    Thanks a lot!


    Greetings
    Daniel
  2. Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 18 Apr 2011 Link to this post

    Hello Daniel,

    Basically, the document has two states depending on if it has been measured or not. Some operations expect that the document has been measured, while others can only be performed on not measured documents. Export of document requires that the document has been measured in advance and documents are not measured on import.
    If you decide to export the document without showing it in the editor first, you would have to manually invoke the following method:

    private void MeasureAndArrangeInDefaultSize(RadDocument document)
    {
        document.Measure(RadDocument.MAX_DOCUMENT_SIZE);
        document.Arrange(new RectangleF(PointF.Empty, document.DesiredSize));
    }

    Note that this is not needed when you assign an imported document to a RadRichTextBox's Document property and show it on screen, as it will get measured by the Silverlight framework and everything will work OK.

    Regards,
    Iva
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Daniel
    Daniel avatar
    2 posts
    Member since:
    Apr 2011

    Posted 21 Apr 2011 Link to this post

    Hello,

    unfortunately this does not solve the issue.
    I included and invoked your method in my code, but the issue is the same. I still get the InvalidCastException.
    You can recreate this scenario, when you try to upload a docx with a table in it, and then try to convert it into a HTML RadDocument.

    My code looks like this:
            private void OnOpenDocumentCommand(object parameter)
            {
                OpenFileDialog dlg = new OpenFileDialog();
                dlg.Multiselect = false;
                dlg.Filter = "DOCX Files (.docx)|*.docx";
     
                if (dlg.ShowDialog() == true)
                {
    
                    Stream data = dlg.File.OpenRead();
                    RadDocument tmpDoc = new DocxFormatProvider().Import(data); 
     
                    MeasureAndArrangeInDefaultSize(tmpDoc);
     
                    string html = new HtmlFormatProvider().Export(tmpDoc);
                    //The following line throws a InvalidCastException:
                    RadDocument tmp2 = new HtmlFormatProvider().Import(html);
                }
            }
    
            private void MeasureAndArrangeInDefaultSize(RadDocument document)
            {
                document.Measure(RadDocument.MAX_DOCUMENT_SIZE);
                document.Arrange(new RectangleF(PointF.Empty, document.DesiredSize));
            }
  4. Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 21 Apr 2011 Link to this post

    Hello Daniel,

    We are not able to reproduce the issue on our end. Could you please open a support ticket of type "General Feedback" and send over a sample document that causes the exception?
    Thank you for the involvement.

    Kind regards,
    Iva
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top