Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Convert a rich text field into text with html tags

1,899 views
Skip to first unread message

Franck LEROY

unread,
Jun 3, 2002, 5:13:09 AM6/3/02
to
Hello,

I have a lot of document with a field in rich text. I want to convert all
the informations for all the documents in that richtext to an other field
but with html tags. The RTF doesn't save the information into html code for
all the documents.
Can I wrote a lotusscript to convert the rtf into html?

Please help

Thanks

Franck LEROY


Robert Chwalczyk

unread,
Jun 3, 2002, 7:00:31 AM6/3/02
to

Franck LEROY wrote:
>
> Hello,
>
> I have a lot of document with a field in rich text. I want to convert all
> the informations for all the documents in that richtext to an other field
> but with html tags. The RTF doesn't save the information into html code for
> all the documents.
> Can I wrote a lotusscript to convert the rtf into html?

if you do so let me know...

I think no.
RTF can contain (layout) information that is not defined in HTML
(TAB...)
Other example:
font sizes (just a few in HTML).

...and what about attachements ?

In my opinion the best way to write this converter is to do it in
java(java agent).


robert

Tom Sanders

unread,
Jun 3, 2002, 6:24:17 AM6/3/02
to

"Franck LEROY" <fle...@isagri.fr> schreef in bericht
news:adfbao$jg9$1...@reader1.imaginet.fr...

FYI: I found this article very useful. I has been posted before in this
group, so I take the liberty to re-post it.
Good luck

Tom


************************************************************
ADVISOR TIPS: LOTUS NOTES & DOMINO - Issue ELN010202
============================================================
+ Parse a Rich Text Field to HTML

************************************************************
+ ADVISOR TIP: Parse a Rich Text Field to HTML
- Lotus Notes 5x
============================================================

With Notes 5x, you can save a rich text field (RTF) as
native HTML/MIME. This can be very useful.

Unfortunately, getting the native HTML from within the RTF
was almost impossible from the client until version 5.0.2.

In version 5.0.2+, Lotus added a class called
NotesMimeEntity that lets you pull the native HTML/MIME
code from the RTF field. This was not documented in 5.0.2
but is documented in 5.0.3+.

If you are running version 5.0.2, you can get the class's
methods/properties via the script editor. Open up the
programmer's pane. Under the Reference tab, find Domino
Classes and look for the NotesMimeEntity class.

Here's a summary of the class properties and methods:

Properties:
String ContentAsText
String ContentSubType
String ContentType
String Headers
Boolean NotesSession.ConvertMime (This either allows or
disallows conversion of text and MIME.)

Methods:
GetFirstChildEntity() as NotesMimeEntity
GetNextSibling() as NotesMimeEntity
GetParentEntity() as NotesMimeEntity

Below is an example of accessing these methods and getting
the HTML from an RTF.
1. Place the code in a button of a form with a field called
"RTF" of type RichText.
2. Set the RTF's field store property to "Store contents
as HTML / Mime." This setting is on the second tab of
the field properties in Domino Designer.
3. Make a second field on the form called "HTMLText" of
type text. If you click the button, a message box displays
the native HTML tags for the RTF field.
4. Populate the HTMLText field with the HTML generated.
5. Populate the RTF with tables, bold, underline, etc..
6. Save the document.
7. Click on the button -- instant HTML! The doc must be in
edit mode for this button to work, or it will generate an
error when it tries to set the HTMLText field.

(Options)
Option Explicit

(Declarations)
Const MIME_TYPE_MULTIPART = "multipart"
Const MIME_TYPE_TEXT = "text"
Const MIME_SUBTYPE_RELATED = "related"
Const MIME_SUBTYPE_HTML = "html"
Const HTML_START = "<HTML>"
Const HTML_FINISH = "</HTML>"
Const HTML_HEADER_START = "<HEAD>"
Const HTML_HEADER_FINISH = "</HEAD>"
Const HTML_BODY_START = "<BODY>"
Const HTML_BODY_FINISH = "</BODY>"
Const HTML_REM_START = "<!-- "
Const HTML_REM_FINISH = " --> "
Const MB_ICONINFORMATION = 64
Const MB_ICONEXCLAMATION = 48

Function GetHtmlFromRTF(thisDoc As Notesdocument,RTFName$)
As String On Error Goto errorHandle

Dim session As New NotesSession
Dim item As NotesItem
Dim mime As NotesMIMEEntity
Dim childMime As NotesMimeEntity
Dim returnString$


Set item = thisDoc.GetFirstItem( RTFName$ )
Set mime = item.GetMimeEntity

session.ConvertMime = False

Select Case Lcase(mime.ContentType)
Case MIME_TYPE_MULTIPART
returnString = GetMultiPartMimeAsHTML(mime)
Case MIME_TYPE_TEXT
returnString$ = HTML_START + Chr$(10)
returnString$ = returnString$ +
HTML_HEADER_START + Chr$(10)
returnString$ = returnString$ +
Chr$(10) + HTML_REM_START + Chr$(10)
returnString$ = returnString$ +
mime.Headers
returnString$ = returnString$ +
Chr$(10) + HTML_REM_FINISH + Chr$(10)
returnString$ = returnString$ +
Chr$(10) + HTML_HEADER_FINISH
returnString$ = returnString$ +
HTML_BODY_START + Chr$(10)
returnString$ = returnString$ +
mime.ContentAsText
returnString$ = returnString$ +
Chr$(10) + HTML_BODY_FINISH
returnString$ = returnString$ +
Chr$(10) + HTML_FINISH
Case Else
returnString$ ="Unknown"
End Select ' mime.ContentType

Set childMime = mime.GetFirstChildEntity

GetHtmlFromRTF = returnString$

Exit Function

errorHandle:
Msgbox "There has been an error: " +
Chr$(13) + "Number: " + Cstr(Err) + Chr$(13) +
"Message: " + Error$, _
MB_ICONEXCLAMATION,_
"Error in [GetHTMLFromRTF]"

GetHtmlFromRTF = "Error"

Exit Function
End Function

Function GetMultiPartMimeAsHTML(parentMime As
NotesMimeEntity)
On Error Goto errorHandle

Dim returnString$, headers$, contentText$
Dim childMime As NotesMimeEntity

Set childMime = parentMime.GetFirstChildEntity

While Not(childMime Is Nothing)
headers$ = headers$ + childMime.Headers
contentText$ = contentText$ + childMime.ContentAsText
Set childMime = parentMime.GetNextsibling()
Wend

returnString$ = HTML_START + Chr$(10)
returnString$ = returnString$ +
HTML_HEADER_START + Chr$(10)
returnString$ = returnString$ +
HTML_REM_START + Chr$(10)
returnString$ = returnString$ + headers$
returnString$ = returnString$ + Chr$(10) +
HTML_REM_FINISH + Chr$(10)
returnString$ = returnString$ + Chr$(10) +
HTML_HEADER_FINISH + Chr$(10)
returnString$ = returnString$ + Chr$(10) +
HTML_BODY_START + Chr$(10)
returnString$ = returnString$ + contentText$
returnString$ = returnString$ + Chr$(10) +
HTML_BODY_FINISH
returnString$ = returnString$ + Chr$(10) +
HTML_FINISH

GetMultiPartMimeAsHTML = returnString$

Exit Function

errorHandle:
Msgbox "There has been an error: " + Chr$(13) +
"Number: " + Cstr(Err) + Chr$(13) + "Message: " + Error$, _
MB_ICONINFORMATION,_
"Error in [GetMultiPartMimeAsHTML]"

GetMultiPartMimeAsHTML = "Error"

Exit Function
End Function

Sub Click(Source As Button)
Dim workspace As New NotesUiWorkspace
Dim doc As NotesDocument
Dim uiDoc As NotesUidocument
Dim html$

Set uiDoc = workspace.currentdocument
Set doc = uiDoc.Document

html$ = GetHTMLFromRTF(doc, "RTF")
Msgbox html$, MB_ICONINFORMATION, "HTML from RTF Field"
Call uiDoc.FieldSetText("HTMLText", html$)
End Sub

--Shane Hollis
Christchurch, New Zealand


************************************************************
Try It FREE!
LOTUS ADVISOR Magazine
************************************************************

Act now and start receiving expert advice and practical
solutions on Lotus technology!

Each issue is packed with all the development techniques
and management practices you need to get the full benefits
of Lotus technology including Notes, Domino, Sametime,
QuickPlace, K-station, Discovery Server, Mobile Notes,
Domino Everyplace, LearningSpace, and more.

Only in LOTUS ADVISOR Magazine -- the authority on Lotus
technology.

Click here for a FREE issue!
http://Advisor.com/Lotus

************************************************************
GOT TIPS?
=========
Share your expertise with colleagues. Submit your tips at
http://Advisor.com/Tips. You just might earn a rare
"I Tipped Advisor" t-shirt to amaze your friends. You can
also register to receive ADVISOR TIPS regularly via e-mail.

============================================================
CHANGE YOUR ADVISOR TIPS
========================

PRIVACY POLICY: Your e-mail, phone, and fax will be used only
by Advisor, and not be given to outsiders without your
explicit permission.

You have received this because you have given Advisor your
e-mail address, and you have requested or indicated an
interest in this information.

To change the topics of your ADVISOR TIPS, go to
http://Advisor.com/Register. Or write to
Advis...@Advisor.com with the subject "change," and tell
us what ADVISOR TIPS you desire. Be sure to include the
exact address this e-mail was sent to. Please keep us
updated on your current interests, needs, and e-mail address.

To stop receiving *ALL* ADVISOR TIPS, go to
http://Advisor.com/Register. Or, reply to
Advis...@Advisor.com with the subject "remove." Be sure
to include the exact address this e-mail was sent to. If you
use multiple addresses, send them too.

If you prefer, you can call us (numbers below) to make
changes.

************************************************************
ADVISOR MEDIA, Inc.
Founded 1983

ADVISOR.COM
"Expert Advice on E-Business & Technology" (tm)

ADVISOR serves business and technology professionals with
dozens of magazines, journals, conferences, seminars, Web
zones and sites, CDs, books, tapes, and e-mail services.

858-278-5600
800-336-6060
858-278-0300 fax

5675 Ruffin Road
San Diego, California 92123

http://Advisor.com
mailto:In...@Advisor.com

============================================================
This document is provided for information only, "as is".
You are solely responsible for determining the suitability
of this information.

"For your eyes only." Please tell your friends to request
their own customized ADVISOR TIPS at
http://Advisor.com/Register.

============================================================
Copyright (C) 2001 ADVISOR MEDIA, Inc. All Rights Reserved.
Advisor, Advisor Tips, Advisor.com, Advisor Media,
Advisor DevCon, Advisor Seminars, Advisor Academy,
Advisor Live, The e-Business Authority, For IT Professionals,
Expert Advice On, and ADVISOR logo are registered trademarks,
trademarks or servicemarks of ADVISOR MEDIA, Inc.
in the United States and other countries.
Trademarks of other companies are their property, and used
for identification purposes only.
============================================================
ELN010202

Franck Leroy

unread,
Jun 3, 2002, 6:39:36 PM6/3/02
to
What type of java agent ithas to be done.
Can you give me some examples or references of java code to use in this
case.
Thanks

Franck

"Robert Chwalczyk" <rchwa...@intarsys.de> a écrit dans le message de news:
3CFB4C4F...@intarsys.de...

Robert Chwalczyk

unread,
Jun 5, 2002, 6:56:05 AM6/5/02
to

Franck Leroy wrote:
>
> What type of java agent ithas to be done.
> Can you give me some examples or references of java code to use in this
> case.
> Thanks
>

A "simple" java agent should do that.
Unfortunately I can not give you some code snippets, because it's a part
of our software, sorry. Tom Sander's article is interesting.

robert

0 new messages