Forum Moderators: coopster

Message Too Old, No Replies

RTF to HTML

Trying to convert RTF text to HTML coding.

         

jatses

10:55 pm on Aug 6, 2006 (gmt 0)

10+ Year Member



Hello! It's been a while since I have had to get on here, but I have a problem that even Google hasn't been able to solve. I've written a VB.NET application as my CMS for my site and it uses a RichTextBox control module for formatting text. I am currently saving the text in RTF format to the database. What I want is to be able to convert it to HTML using PHP so it can be displayed just like it was formatted. The site is using a BLOG type system. I put in an update subject/title and then the actual information goes in the body with all the formatting I can apply to it. I've tried converting it to HTML with VB.NET, but the only available class is $400 or way out-dated and Google doesn't give me any usable scripts. Any help would be much appreciated. Also, I would like to keep it free if at all possible. Thanks for viewing and helping!

Jatses

scriptmasterdel

6:03 pm on Aug 7, 2006 (gmt 0)

10+ Year Member



I am willing to help, i may not be that usefull ... but it don't seem like anyone else has taken an interest in this post.

Let me ask some questions.

Where are your RTF files stored?
.... If they are stored in the DB, how are they stored? Text field?

Do you want the files to be dynamically created from the DB or what?

Del

jatses

6:55 pm on Aug 7, 2006 (gmt 0)

10+ Year Member



Where are your RTF files stored?
~ The RTF text is stored in a text field in a MySQL DB.

Do you want the files to be dynamically created from the DB or what?
~ I just want PHP to convert the text from RTF format to HTML.

Like I tried to state earlier (with a different scenario), I have a VB.NET application that I login to so I can add new products to the DB. Now, each product has a description and some of the words in the description I want to have emphasized (whether bold, italics, different color, size, font, or highlighted). In order to do that in VB.NET I had to use a RichTextBox control which formats the text in RTF. I am unable to convert the RTF text from that control into HTML in VB.NET so I am just saving it to the DB in a text field with the RTF formatting. So, what I want is to use PHP to convert the product description from RTF to HTML. Right now I don't care if I only do it once and then resave it to the DB or I do it dynamically each time the product description is displayed. Hope this makes better since. Thanks for viewing and helping!

Jatses

john_k

7:23 pm on Aug 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



RTF is a markup language, so it is not extremely difficult to convert between the two. For things like bold, italics, and underline, you can pretty much do a one-for-one swap of the HTML start/stop tags for the RTF.

If you want to keep it all CSS, and avoid using html font tags, then you will need to create html span or div tags (with a style attribute) when you have font typeface, size, and/or color changes.

The conversion algorithm should be straight forward. You scan the RTF raw text looking for "{" characters. When you find one, look for the closing "}". Then determine which RTF tag(s) are involved and write the corresponding HTML tag(s).

When multiple changes are applied to the same block of text, RTF will put it all into one set of {}. Much like a the style attribute of an HTML entity.

You should be able to track down a list of possible RTF codes on the internet somewhere. Alternatively, you could create a few test documents with the interface you have created and then inspect it as a text file.

If I recall, the best source I could find for RTF codes was the help compiler documentation for VB 1.0. (yes, 1.0 - the help editor was an optional add-on that you had to pay $50 for. So I guess they felt they had to actually document it)

Sorry I can't be more specific. It has been at least 8 years since I have done any RTF conversions, and I did a memory dump a while ago to make room for other stuff. :)

jasonf

1:27 am on Aug 9, 2006 (gmt 0)

10+ Year Member



Why not look at WYSIWYG Editors that do the conversion for you?

I know there are Open Source ones around like FckEditor & TinyMC(?) that do the trick fairly well.

HTH.

Jason

coopster

2:48 pm on Aug 21, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



TinyMC(?)

Close! TinyMCE ;)

Welcome to WebmasterWorld, jasonf.

yukti

6:51 am on Aug 24, 2006 (gmt 0)

10+ Year Member



Hi
Even I am lookng for the script to convert RTF to TEXT or RTF TO HTML
Can anyone help please .