Outputting RTF image data stream as ASCII

  • Hi,

    I've been working with your TextDynamic control and all seems to be well for text based documents. However, I am unable to store the RTF data in a C# string. Is there a way to do this?

    When I save the file using SaveToFile() the file saves correctly. MS Word will open this file but Wordpad and other RTF tools will not. I believe this is because the output from TextDynamic writes the binary data out as 8-bit data bytes. MS word and Wordpad write their binary data out as ASCII encoded data. e.g.:

    A byte with all bits set would be written out as the two ASCII characters 'FF'. In this way, the RTF is a pure ASCII document that can contain binary data.

    There is also a _huge_ discrepency in the size of your file and the same file generated by other tools. Your file is 62k and MS Word / Wordpad generates a 4.5 meg file (it's a reasonably large image).

    Because of the above, when I take your Stream2WPStream to store the data in a MemoryStream everything is fine. When I come to convert that to a C# string it quite naturally terminates on the first null (0) character it finds, and all the binary data is discarded.

    Is there an interface method I can call to do this conversion. I really need the file written out in the more normal way as other components expect an ASCII data stream, and not all our customers use MS Word.

    Also, I'm sending the RTF data to a third party control and the header and footer information is not appearing. Is this not part of the RTF data? I can see the header and footer text in the actual data, but it doesn't appear to get to the other side.

    Any help pointing me in the right direction would be greatly appreciated.

    Cheers,

    Tim.

    • Offizieller Beitrag

    Hi,

    C# strings are always two-byte which makes them a suboptimal choice to store RTF code (which is always ANSI code). You can use SaveToVar to save to a byte[] array.

    When you want to avoid binary data in the RTF use

    SaveToFile( ..., 'RTF-nobinary')

    This works likewise for SaveToString and SaveToVar.

    Julian