HTMLConvertItem - From RichText to HTML using API

Hi to all, I use this API for convert my RichText.In my RichText I have created a TABLE with 2 row and 2 colum…

If my “rich-text is stored MIME” the API return correctly the HTML string

If my “rich-text” is normal…the API return a wrong markup…with
istead of every …

Have you any suggest for my problem?

Tnx You

P.S. I read the Julian Blog…for this particular solution

http://www.nsftools.com/blog/blog-07-2008.htm#07-15-08

Subject: notes rich text tables should convert to HTML

by “rich-text is stored MIME” I assume you mean the fieldproperty you set in the designer.

If a field is set to “rich-text is store as MIME” then the

notes editor converts to HTML when the item is saved.

The HTMLConvertItem call will just read the item and return the HTML.

Can you try accessing the items with a browser?

(Start up the http server, submit the appropriate URL, etc.)

Subject: This isn’t my problem…

My problem is a techical problem for the API.For me this is a BUG of this function API so that I have post this discussion…

Subject: sorry, I wasn’t clear …

When you use HTMLConvertItem on a rich text item, tables should show up with TABLE, TR and TD tags as you

would expect.

In other words there is no bug in the API itself.

There must be some other explanation of why you are

seeing BR instead.

The HTML API is a C API. Perhaps the lotuscript access to it

is causing some change to the data. Or perhaps some other

step you took changed the content.

If you look at the item with the notes client do you see the

table?

If you look at the item from a browser do you see the table?

(Does a view source from the browser show the TABLE and associated

tags?)

Subject: I see table in browser and client

In Client I see the table and in a Browser I see the table…

With this API ( that I use in Client and write in a File TXT I don’t see the TAG …But
)

This Is the code ( It’s egual to Julian )

If I use the “HtmlConvertNote” on the same document…I see the TAG HTML but with all the other information…

Declaration:


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

( Byval NullPort As Long, Byval Server As String, Byval FIle As String, _

Byval PathNet As String) As Integer

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

( Byval PathName As String, DbHandle As Long) As Integer

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

( Byval DbHandle As Long) As Integer

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

( HtmlHandle As Long) As Integer

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

( Byval HtmlHandle As Long) As Integer

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

( Byval HtmlHandle As Long, Byval DbHandle As Long, Byval NoteHandle As Long, _

Byval UrlArgsCount As Long, Byval NullUrlArgs As Long) As Integer

Declare Function HTMLGetPropertyLong Lib “NNOTES” Alias “HTMLGetProperty” _

( Byval HtmlHandle As Long, Byval PropertyType As Long, RetVal As Long) As Integer

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

( Byval HtmlHandle As Long, Byval StartingOffset As Long, TextLength As Long, _

Byval RetVal As String) As Integer

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

( Byval HtmlHandle As Long, Byval DbHandle As Long, Byval NoteHandle As Long, _

Byval FiledItem As String) As Integer

'** Error code masks

Const ERR_MASK = &H3fff

Const PKG_MASK = &H3f00

Const ERRNUM_MASK = &H00ff

Declare Function OSLoadString Lib “nnotes.dll” (Byval hModule As Long, Byval stringCode As Integer, _

Byval retBuffer As String, Byval bufferLength As Integer) As Integer

Function


Function ConvertItemToHtml(doc As NotesDocument, itemname As String) As String

'** create a proper network path name with OSPathNetConstruct

Dim db As NotesDatabase

Dim hDb As Long

Dim pathName As String

Set db = doc.ParentDatabase

pathName = String(256, " ")

Call OSPathNetConstruct(0, db.Server, db.FilePath, pathName)



'** open the database and get a handle with NSFDbOpen (if you're doing this

'** to a lot of documents, you should try to only open the database once)

Dim result As Integer

result = NSFDbOpen(pathName, hDb)

If result <> 0 Then

	Messagebox "Cannot open database " & db.FilePath & " on server " & db.Server & _

	". Error was " & Cstr(result) & ": " & GetAPIError(result)

	Exit Function

End If



'** create an HTML Converter

Dim converter As Long

result = HtmlCreateConverter(converter)

If result <> 0 Then

	Messagebox "Cannot create HTML Converter" & _

	". Error was " & Cstr(result) & ": " & GetAPIError(result)

	Goto closeDb

End If



'** convert the doc to HTML (I'm taking a shortcut with doc.Handle here;

'** you may want to consider using NSFNoteOpen or similar)

result = HTMLConvertItem(converter, hDB, doc.Handle, itemname)

If result <> 0 Then

	Messagebox "Cannot convert note " & doc.UniversalID & " to HTML" & _

	". Error was " & Cstr(result) & ": " & GetAPIError(result)

	Goto destroyConverter

End If



'** figure out how long the resulting HTML is

Dim textLength As Long

result = HtmlGetPropertyLong(converter, 0, textLength)

If result <> 0 Then

	Messagebox "Cannot determine HTML Converter text length" & _

	". Error was " & Cstr(result) & ": " & GetAPIError(result)

	Goto destroyConverter

End If



'** send the converted HTML to a string

Dim finalString As String

Dim chunk As String

Dim chunkSize As Long

Dim startPos As Long

chunkSize = 1024		'** adjust chunkSize to meet your comfort level

Do While (startPos < textLength)

	If ((textLength - startPos) < chunkSize) Then

		chunkSize = textLength - startPos

	End If

	chunk = String(chunkSize, " ")

	result = HtmlGetText(converter, startPos, chunkSize, chunk)

	If result <> 0 Then

		Messagebox "Cannot get HTML text between " & startPos & " and " & (startPos + chunkSize) & _

		". Error was " & Cstr(result) & ": " & GetAPIError(result)

		Goto destroyConverter

	End If

	finalString = finalString & Left(chunk, chunkSize)

	startPos = startPos + chunkSize

Loop



ConvertItemToHtml = finalString

'** this is API work, so make sure you do the appropriate cleanup when you’re done

destroyConverter:

Call HTMLDestroyConverter(converter)

closeDb:

Call NSFDbClose(hDb)

endOfFunction:

Exit Function

End Function

Subject: I cannot reproduce the problem

I took Julian’s agent modified it to 1) write to a text file,and 2) open a document of my choosing using GetDocumentById.

(So I could supply a document that has a table in it)

I ran the agent and saw the document in the text file.

The table was converted properly

Then I added the “Declare Function” for HTMLConvertItem and

changed ConvertDocToHtml to use HTMLConvertItem.

I ran the agent again and the text file no has just the content

of the item, including the table with the proper HTML.

Subject: OK now it’s ok…but…

I have resolve and now the API return the correctly result… ( the problem is that the RichText are damage,i don’t know so that i have recreated)But now I have another question :

How I can capture corretly the special char ( for example è, ì, etc…)

now the function return ŠŠŠŠŠ 

tnx

Subject: htmlapi returns LMBCS

so you will need to convert LMBCS to the character set you are using.

This is assuming that the item is in fact

rich text, not MIME.

I recommend that you look at the item type

and if it is MIME, just use the MIME APIs

to get the content, don’t use the HTMLAPI.

Be sure to set the NotesSession.ConvertMIME

proerty is set to FALSE. Otherwise, the MIME item will be converted to rich text and then back to HTML by the HTML API

Subject: Tnx You

Fantastic!Now I have used the API

OSTranslate for translate !!!

Tnx You very much for your best support!!! :smiley:

Subject: I can