Convert word to rtf c#
Get via App Store Read this post in our app!
How to convert a string to RTF in C#?
How do I convert the string "Européen" to the RTF-formatted string "Europ\'e9en"?
What I have found so far
RichTextBox can be used for certain things. Example:
But then rtfFormattedString turns out to be the entire RTF-formatted document, not just the string "Europ\'e9en".
I've also found a bunch of other resources on the web, but nothing quite solved my problem.
Had to add Trim() to remove the preceeding space in result . Other than that, Brad Christie's solution seems to work.
I'll run with this solution for now even though I have a bad gut feeling since we have to SubString and Trim the heck out of RichTextBox to get a RTF-formatted string.
Logic as an extension method:
Doesn't RichTextBox always have the same header/footer? You could just read the content based on off-set location, and continue using it to parse. (I think? please correct me if I'm wrong)
There are libraries available, but I've never had good luck with them personally (though always just found another method before fully exhausting the possibilities). In addition, most of the better ones are usually include a nominal fee.
Kind of a hack, but this should get you through what you need to get through (I hope):
- Header
- \f0 - Use the 0-index font (first font in the list, which is typically Microsoft Sans Serif (noted in the font table in the header: <\fonttbl<\f0\fnil\fcharset0 Microsoft Sans Serif;>> ))
- \fs17 - Font formatting, specify the size is 17 (17 being in half-points)
- Footer
- \par is specifying that it's the end of a paragraph.
Hopefully that clears some things up. ;-)
This is how I went:
I think using a RichTextBox is:
2) I don't like RichTextBox after spending days of trying to make it work with an RTF document created in Word.
Below is an ugly example of converting a string to an RTF string:
I know it has been a while, hope this helps..
This code is working for me after trying every conversion code I could put my hands on:
titleText and contentText are simple text filled in a regular TextBox
rtb.rtf now holds the rtf text.
The following code will save the rtf text and allow you to open the file, edit it and than load it back into a RichTextBox back again:
I found a nice solution that actually uses the RichTextBox itself to do the conversion:
Not the most elegant, but quite optimal and fast method: