Importing html to richtext field

I’m trying to import some html formatted text into a richtext field using LotusScript and would like to preserve the formatting. I’m aware of the uidoc import method but I need to do this in a background server agent. I have also looked at mimeentity but it appears that you cannot sign or mail the document afterwards. Is there an easy way to render html to rtf using script?

Thanks,

Jeff

Subject: Importing html to richtext field

Here is some simple code to import a straight HTML ascii file into a Rich Text Field in a form called “Memo”. What you do with it once there is up to you - I am using this code as part of a mail-merge function to take HTML generated by MS Word, personalize it from a Notes database source, and email it out. It is activated by an action from another document that contains some parameters that my mail-merge needs, but you could bypass all of the references to “curdoc” in the code.

Hope this all helps.

Type EditImportData

FileName As String * 100

FontID As Long

End Type

Declare Function ImportHtmlTextFile Lib “NIHTML” Alias “ImportHtmlTextFile”_

( D As EditImportData, Byval F As Integer, Byval M As Long, Byval A As String, Byval N As String) As Integer

Declare Sub NEMDisplayError Lib “NNOTESWS” Alias “NEMDisplayError” ( Byval S As Integer)

Declare Function MailAddMessageBodyComposite Lib “NNOTES” Alias “MailAddMessageBodyComposite” _

( Byval hM As Long, Byval N As String, Byval F As String) As Integer

Sub Click(Source As Button)

Dim session As New NotesSession

Dim workspace As New NotesUIWorkspace

Dim uidoc As NotesUIDocument

Dim curdoc as NotesDocument

Dim doc as NotesDocument

Set uidoc = workspace.CurrentDocument

Set curdoc = uidoc.Document

Set doc = New NotesDocument(session.CurrentDatabase) ' create a new document to contain the import

infile$= curdoc.ImportFileName(0)  'this is the name of the file to be imported - in my case it's a variable, but you could make it a constant like "C:\InputDocument.htm"

Set rti = New NotesRichTextItem(doc, "Body") ' create a rich text object

With doc

	.Subject=curdoc.Subject(0)

	.Form = "Memo"

	Call	ImportHTMLFile(doc, infile$, "Body") ' this is where the import happens

	rti.IsSigned = False

	rti.IsEncrypted = False

		

	Call workspace.EditDocument(True, doc,,,True)

End With

End Sub

Sub ImportHTMLfile(doc,filename$, field$)

Const temp = "C:\TEMP\NOTESCD.TMP"



Dim D As EditImportData

D.FileName = temp



s% = ImportHtmlTextFile(D, 3, 0, "", filename$)

If Not s% = 0 Then

	NEMDisplayError s%

	Exit Sub

End If



With doc

	

	s% = MailAddMessageBodyComposite(.Handle, field$, temp)

	If Not s% = 0 Then

		NEMDisplayError s%

		Exit Sub

	End If

	

End With



Kill temp

End Sub

Subject: Very slick code, thanks!

Worked like a charm with slight modification. Thanks for sharing…

Subject: RE: Importing html to richtext field

Thanks, this code works pretty well for me. The only problem I’ve discovered is that the full text indexer can’t touch the field containing the imported HTML. However, if I open the doc in the Notes client and save it then the server is able to index.

Any ideas?

Thanks,

Mike