Insert images / files inside Notes document using lotus.domino

3.5k views Asked by At

I am trying to insert some inline image and inline attachment inside Notes document, using Rich Text format by lotus.domino package Java API, and send it.

The code of inserting is as below.

// Insertion by RichTextItem.embedObject()

RichTextItem rti = (RichTextItem) doc.getFirstItem("Body");
RichTextNavigator rtnav;
rtnav = rti.createNavigator();
rtnav.findFirstElement( .../*Somewhere inside document*/ );
rti.beginInsert(rtnav);
rti.embedObject(EmbeddedObject.EMBED_ATTACHMENT,null, "C:\\TEMP\\abc.jpg", "InlineImageOrAttachment"); // insert file which is jpg/png/pdf/doc...etc
rti.endInsert();

Right now I have got: enter image description here

What I want to have is: enter image description here

Thanks in advance.

1

There are 1 answers

0
Doug Brammer On

Here is a LotusScript function I found on the net. the same classes should be available in Java:

Function EmbedPictureIntoRichText(doc As NotesDocument,strFilePath As String)
       EmbedPictureIntoRichText = False
       Dim session As New NotesSession
       Dim db As NotesDatabase
       Dim body As NotesMIMEEntity
       Dim header As NotesMIMEHeader
       Dim child As NotesMIMEEntity
       Dim stream As NotesStream
       Dim fileFormat As String
       Dim rtitemA As NotesRichTextItem
       Dim rtitemB As NotesRichTextItem

       session.Convertmime = True
       Set db = doc.parentdatabase
       Set stream = session.CreateStream
       Call stream.Open(strFilePath)
       Set body = doc.CreateMIMEEntity("DummyRichText")
       Set header = body.CreateHeader("Content-Type")
       Call header.SetHeaderVal("multipart/mixed")
       Set child = body.CreateChildEntity()
       fileFormat = "image/jpeg"
       Call child.Setcontentfrombytes(stream, fileFormat, 1730)
       Call stream.Close()
       Call doc.save(False, False)
       Set rtitemA = New NotesRichTextItem(doc,"Photo")
       Set rtitemB = doc.GetFirstItem("DummyRichText")
       Call rtitemA.AppendRTItem( rtitemB )
       Call rtitemB.Remove()
       Call doc.save(False, False)
       EmbedPictureIntoRichText = True
End Function