Profile Picture

NRichTextView having issues saving RTF string

Posted By Tom Galczynski 5 Years Ago
Author
Message
Tom Galczynski
Problem Posted 5 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)

Group: Forum Members
Last Active: 4 Years Ago
Posts: 29, Visits: 87
Hello. I'm using the NRichTextView control to construct a 3x2 table with string data in each cell.
The problem is when I extract the RTF string from the widget, I save it to a column in a SQL table,
and when I subsequently push that string back to the control when opening my form, it only shows the
first column of the table. Here are the properties I amusing in my code to get and set the RTF string
in the NRichTextView:

  Public Property Rtf As System.String
   Get
    Dim currentFormat As RichTextEdit.DocumentFormats = Me._format

    Try

      Me.Format = DocumentFormats.Rtf

      Using ms As System.IO.MemoryStream = Me.Stream
       Return _encoding.GetString(ms.ToArray)
      End Using

    Finally

      Me.Format = currentFormat

    End Try
   End Get
   Set(value As System.String)
    Dim currentFormat As RichTextEdit.DocumentFormats = Me._format

    Try

      Me.Format = RichTextEdit.DocumentFormats.Rtf
      Using ms As New System.IO.MemoryStream(_encoding.GetBytes(value))
       Me.Stream = ms
      End Using

    Finally

      Me.Format = currentFormat

    End Try
   End Set
  End Property

  Public Property Stream As System.IO.MemoryStream
   Get

    Dim richTextView As Nevron.Nov.Text.NRichTextView = Me._currentView

    If richTextView IsNot Nothing Then
      Dim currentLayout As Nevron.Nov.Text.ENTextLayout = richTextView.Content.Layout
      Try
       richTextView.Content.Layout = Me._currentLayout
       Dim MS As New System.IO.MemoryStream
       richTextView.SaveToStream(MS, Me.DocumentFormat)
       Return MS
      Finally
       richTextView.Content.Layout = currentLayout
      End Try
    End If

    Return Nothing
   End Get
   Set(value As System.IO.MemoryStream)

    If value IsNot Nothing Then

      Dim richTextView As Nevron.Nov.Text.NRichTextView = Me._currentView

      If richTextView IsNot Nothing Then
       richTextView.Content.Sections.Clear()
       richTextView.LoadFromStream(value, Me.DocumentFormat)
       Me._currentLayout = richTextView.Content.Layout

       If Me._navigation = NavigationView.None Then
        'When displaying the plain control, display the contents in web view so scrollbars, etc. work properly.
        richTextView.Content.Layout = Nevron.Nov.Text.ENTextLayout.Web
       End If

      End If

    End If

   End Set
  End Property

It doesn't matter if I construct the table programatically or in the GUI the result is the same. Is there
anything I can do to prevent this from happening? The encoding is UTF8. Any hints would be appreciated.

Thanks!

Tom G.
 

Nevron Support
Posted 5 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: 5 days ago @ 4:39 AM
Posts: 3,054, Visits: 4,018
Hi Tom,
Apologies for the delayed response - we had some technical issues with the forum.

We tested with a simple RTF roundtrip and a simple table:
   MemoryStream stream = new MemoryStream();
    nRichTextViewWithRibbonControl1.Widget.View.SaveToStream(stream, new NRtfTextFormat());
    stream.Seek(0, SeekOrigin.Begin);


    nRichTextViewWithRibbonControl1.Widget.View.LoadFromStream(stream, new NRtfTextFormat(), null);
and the control imported a table with the same dimensions (the Allow Spacing Between Cells did not roundtrip correctly though). Can you send us the control contents in some other format (docx or nevron) to test whether the problem is related to the content being serialized somehow?

Best Regards,
Nevron Support Team



Tom Galczynski
Posted 5 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)

Group: Forum Members
Last Active: 4 Years Ago
Posts: 29, Visits: 87
Thanks for the response.  I am fairly sure the problem is not a bug but some sort of setting/property I am not utilizing correctly. Let me show you what the table looks like after I have created it in the program:

When I create the above, I then write the rtf string to a file as a test.  When I try to open that file in WordPad I get this:
https://www.nevron.com/forum/uploads/images/e57f8118-2d57-4abe-a3a5-c08e.jpg

I am able to write to a file using Html and PDF formatting and the output opens up correctly.  Only rtf and docx do not work for me with tables.  If you would like the rtf string to review let me know.  If you can just think of possible causes of this behavior I would appreciate it.  Thank you very much.


Nevron Support
Posted 5 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: 5 days ago @ 4:39 AM
Posts: 3,054, Visits: 4,018
Hi Tom,
Can you send us the rtf file for review - also what happens when you open that document in Word? Wordpad does not process tables well...

Best Regards,
Nevron Support Team



Tom Galczynski
Posted 5 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)

Group: Forum Members
Last Active: 4 Years Ago
Posts: 29, Visits: 87
I have attached the output file.  When I open it in Word, it just shows a long vertical line where the table should be.
Thank you!


Attachments
016316.rtf (369 views, 12.00 KB)
Nevron Support
Posted 5 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: 5 days ago @ 4:39 AM
Posts: 3,054, Visits: 4,018
Hi Tom,
Indeed there is a problem with this rtf - the cellx rtf tag is set to zero meaning that all cells widths are exported as zero. This confuses Word/Wordpad. The core problem is that the document is being exported before it is evaluated. We have fixed this issue and it will not appear in next versions. For the time being you can workaround the problem by forcing the document to evaluate before export:

nRichTextViewControl1.Widget.document.Evaluate();
nRichTextViewControl1.Widget.SaveToFile(@"c:\temp\testtable.rtf", new NRtfTextFormat());

Hope this helps - let us know if you have any questions or meet any problems.

Best Regards,
Nevron Support Team



Tom Galczynski
Posted 5 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)Forum Newbie (0 reputation)

Group: Forum Members
Last Active: 4 Years Ago
Posts: 29, Visits: 87
I've added the call to Evaluate to the Get of my Stream property and in my limited testing it seems to work!:
Public Property Stream As System.IO.MemoryStream
   Get

    Dim richTextView As Nevron.Nov.Text.NRichTextView = Me._currentView

    If richTextView IsNot Nothing Then
      Dim currentLayout As Nevron.Nov.Text.ENTextLayout = richTextView.Content.Layout
      Try
       richTextView.Content.Layout = Me._currentLayout
       Dim MS As New System.IO.MemoryStream
       richTextView.document.Evaluate()
       richTextView.SaveToStream(MS, Me.DocumentFormat)
       Return MS
      Finally
       richTextView.Content.Layout = currentLayout
      End Try
    End If

    Return Nothing
   End Get

I can save the rtf string to the database, retrieve it and push to the control and it looks the same.  I will let you know if I run into any other issues.  Thank you very much for finding this. :-)

Best Regards,
Tom Galczynski




Similar Topics


Reading This Topic