Jump to content

RTF2HTML Conversion


Recommended Posts



  • *Version .4 - Added automatic WMF -> JPG handling, fixing of HTML code to change
  • WMF to JPG exteions; tested Word and Wordpad RTF, and they are compatible;
  • Tested embeded images, JPG/BMP/WMF/EMF/GIF all embed, but Smart Art (2007) does not.
  • Tables work, but table formatting (background/color) does not.
  • Version .3 -- Initial Autoit Forum Release

Was trolling around this board, looking for code that could help with this, and didn't find too much. Wanted to be able to add it to my new chat app that i'm coding in Autoit. (The chat app's purpose is to provide HTML chat interface for Jabber conference rooms.)

So, I looked around sf.net (sourceforge) and found a great project for RTF2HTML lite :D It REQUIRES the RTF and HTML to be files for the conversion, but it's pretty dang quick, and gets the job done.

What it can do:

  • Bold
  • Italics
  • Underline
  • Strikethrough
  • Bullets - see note
  • Text Colors
  • Center, Left, Right alignment
  • Font Sizes
  • Font changes (name, etc)
What I havn't made it do yet:

  • Add Images (tho the dll does support image conversion with an embded folder, which i do have in the include file)
  • Background Colors (Have to code how to pull those from the RTF control, and then i can just replace them into the code before writing the final HTML code :D
What I had to hack around to get done:

  • Pull the first color in the RTF box, convert it from RGB to Hex, insert in into the HTML code, and recompile the HTML output (because the dll seems to like to miss .c11 color lol)

  • r2h.dll
  • mscomct2.ocx
  • r2h.au3
Unimplemented RTF Features (To Do) (dll limitation, not autoit)

  • Better support for OpenOffice Writer's RTF and Linux word processors, including buggy ones.
  • "Table tag not closing" bug with OpenOffice's RTF.
  • Prevent code from stupid RTF writers to generate redundant style references like f3 c4 f3 c4 f3 c4.
  • Always add HTML <TITLE>; and META tags into header.
  • Paragraph borders.
  • Table cell size control.
  • Table borders.
  • Page Headers and Footers (not sure if needed at all).
  • Support for hyperlinks (Microsoft-specific tags and/or automatic URL detection).
  • HREF/SRC URL-encoding (usually not needed).
  • Header (<H1>, <H2>...) tags (header formatting already works OK, but HTML header tags are not used).

Examples really are not needed, because as long as you have the RTF, it should convert it (assuming you used the mscomct2.ocx to output the RTF (tho wordpad and word seem to work fine with it too).

Example: Pulling the RTF from an embded mscomct2.ocx RTF control (using example in help file)

FileWrite(@TempDir & "\r2h.rtf", $oRP.TextRTF)
$code = r2h(@TempDir & "\r2h.rtf", @TempDir & "\r2h.html")

Attached Files

r2h.au3 The function

RTFEditor.au3Very very basic (and isn't complete or foolproof editor)

r2h.dllRTF2HTML dll file.


I have it set to autolaunch the HTML it generates, but you can remove it by removing the ShellExecute($HTML) line in the included file ;)

Edited by zackrspv

-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

Link to comment
Share on other sites

Added more functionality for version .4; check main post for updates.


*Handles images a bit better, with embedded and non embedded folders

*Handles WMF -> JPG conversion

*Changes HTML source to fix WMF -> JPG conversion

*Fixed function description and name; fixed R2H to _R2H, and fixed meaning of flag #1 (inserts image size from RTF code into the HTML Image code, dll still converts it using whatever manner it needs for WMF (default is converting from original to screen resolution)

-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

Link to comment
Share on other sites

  • 1 year later...

You could get the RTF from the clipboard and write it to a temp file. Then, run the conversion on the temp file.

See here on getting the RTF from the clipboard.

Link to comment
Share on other sites

  • 1 month later...


this looks like a useful tool for a project I'm working on, but I haven't been able to suss out how to use it!

[edit] I've answered my original question, so deleted it.

However, I do have a further small query about mscomct2.ocx.

Does this have to be installed in \windows\system and registered in windows, or will it work OK sitting in @scriptdir?

I've installed the dll to @scriptdir

and added to windows\system and registered it on my PC and it works fine, but ideally I'd like not to have to do this on all the PCs [and possibly a server too] on which my app will be running on.

Many thanks for a useful UDF,


Edited by saywell
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...