Rtf To Html

This code will convert Rich Text to HTML, it's quite basic, but it gives you
the basis to work on. I didn't create this code myself, although I have tweaked
it. I originally found it on the web somewhere for Visual Basic, but as it
stands it should work perfectly in Lotus Script. I hope you find it useful.

Chris
Function RTF2HTML(strRTF As String) As String

Dim strHTML As String
Dim l As Long
Dim lTmp As Long
Dim lRTFLen As Long
Dim lBOS As Long 'beginning of section
Dim lEOS As Long 'end of section
Dim strTmp As String
Dim strTmp2 As String
Dim strEOS'string To be added to End of section
Const gHellFrozenOver = False'always false
Dim gSkip As Boolean 'skip To Next word/command
Dim strCodes As String'codes For ascii To HTML char conversion


strCodes = " {00}? {a9}? {b4}? {ab}? {bb}? {a1}?{bf}?{c0}?{e0}?{c1}"
strCodes = strCodes & "?{e1}? {c2}? {e2}?{c3}?{e3}? {c4}? {e4}? {c5}?
{e5}? {c6}"
strCodes = strCodes & "? {e6}?{c7}?{e7}?{d0}?{f0}?{c8}?{e8}?{c9}?{e9}?
{ca}"
strCodes = strCodes & "? {ea}? {cb}? {eb}?{cc}?{ec}?{cd}?{ed}? {ce}?
{ee}? {cf}"
strCodes = strCodes & "? {ef}?{d1}?{f1}?{d2}?{f2}?{d3}?{f3}? {d4}?
{f4}?{d5}"
strCodes = strCodes & "?{f5}? {d6}? {f6}?{d8}?{f8}?{d9}?{f9}?{da}?{fa}?
{db}"
strCodes = strCodes & "? {fb}? {dc}? {fc}?{dd}?{fd}? {ff}? {de}? {fe}?
{df}? {a7}"
strCodes = strCodes & "? {b6}? {b5}?{a6}?{b1}?{b7}?{a8}? {b8}? {aa}?
{ba}?{ac}"
strCodes = strCodes & "?{ad}? {af}?{b0}? {b9}? {b2}? {b3}?{bc}?{bd}?{be}
? {d7}"
strCodes = strCodes & "?{f7}? {a2}? {a3}?{a4}?{a5}"
strHTML = ""


lRTFLen = Len(strRTF)
'seek first line with text on it
lBOS = InStr(strRTF, vbCrLf & "\deflang")
If lBOS = 0 Then Goto finally Else lBOS = lBOS + 2
lEOS = InStr(lBOS, strRTF, vbCrLf & "\par")
If lEOS = 0 Then Goto finally
While Not gHellFrozenOver
strTmp = Mid(strRTF, lBOS, lEOS - lBOS)
l = lBOS
While l <= lEOS
strTmp = Mid(strRTF, l, 1)
Select Case strTmp
Case "{"
l = l + 1
Case "}"
strHTML = strHTML & strEOS
l = l + 1
Case "\"'special code
l = l + 1
strTmp = Mid(strRTF, l, 1)
Select Case strTmp
Case "b"
If ((Mid(strRTF, l + 1, 1) = " ") Or (Mid(strRTF, l +
1, 1) = "\")) Then
strHTML = strHTML & "<B>"
strEOS = "</B>" & strEOS
If (Mid(strRTF, l + 1, 1) = " ") Then l = l + 1
ElseIf (Mid(strRTF, l, 7) = "bullet ") Then
strHTML = strHTML & "?"'bullet
l = l + 6
Else
gSkip = True
End If
Case "e"
If (Mid(strRTF, l, 7) = "emdash ") Then
strHTML = strHTML & "?"
l = l + 6
Else
gSkip = True
End If
Case "i"
If ((Mid(strRTF, l + 1, 1) = " ") Or (Mid(strRTF, l +
1, 1) = "\")) Then
strHTML = strHTML & "<I>"
strEOS = "</I>" & strEOS
If (Mid(strRTF, l + 1, 1) = " ") Then l = l + 1
Else
gSkip = True
End If
Case "l"
If (Mid(strRTF, l, 10) = "ldblquote ") Then
strHTML = strHTML & "?"
l = l + 9
ElseIf (Mid(strRTF, l, 7) = "lquote ") Then
strHTML = strHTML & "?"
l = l + 6
Else
gSkip = True
End If
Case "p"
If ((Mid(strRTF, l, 6) =
This was last published in November 2000

Dig Deeper on Domino Resources

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchDataCenter

SearchExchange

SearchContentManagement

Close