nongkook
nongkook

Reputation: 41

Lotusscript : Can I detect picture in rich text field?

I have a problem with my program that because my user like to attach the screen-capture picture into rich-text field

ex.

enter image description here

And my program can not detect them...

enter image description here

Can everyone share your idea ?...

thank you.

Upvotes: 0

Views: 1898

Answers (2)

DonMaro
DonMaro

Reputation: 117

Seems that (still) the only method to get a handle to these embedded/in-line images is to use the DXL Exporter: https://help.hcl-software.com/dom_designer/12.0.0/basic/H_NOTESDXLEXPORTER_CLASS.html

From there, this documentation might point in the right direction to getting the file out (even if there are no $File attachments as mentioned there; but the data has to be stored somewhere):
https://www.agecom.com.au/support/agecomkb.nsf/0/58cbf10f0ab723c9ca25803e006c7de8?OpenDocument


Or, during my further search, I found a working function here:
https://atnotes.de/index.php?topic=55904.msg360470#msg360470
Code just in case above page gets unavailable sometime:

Function ExportPictures(doc As NotesDocument, path As String) As Variant
' ==================================================================
' Exports GIF and JPG images from a notes document into given destinationPath
' Picture's filename is path\<docid>_<number>.<extension>
' Tempfile used is path\Base64.tmp which is deleted after export
' Returns a list of strings containing filenames of exported pictures (if any)
' Base64 conversion is performed with Notes internal MIME functions, therefore 
' a tempdoc is created but not saved
' ==================================================================
' by Guido Purper August 2005
' ==================================================================
Dim doc2 As NotesDocument
Dim filename As String
Dim fileNum As Integer
Dim counter As Integer
Dim destinationPath As String
Dim stream As NotesStream
Dim mimeEntity As NotesMIMEEntity
Dim fileList List As String
Dim k(1 To 3, 1 To 3) As String
Dim i As Integer
Dim exporter As NotesDXLExporter
Dim dxl As String, dxlPicture As String, dxlPictureType As String
Dim key As String
Dim p1 As Long, p2 As Long

On Error GoTo errorHandler

Set exporter = session.CreateDXLExporter
exporter.ConvertNotesBitmapsToGIF = True

' Initialize some variables
ExportPictures = ""
Erase fileList
' === Key for imported GIFs ===
K(1,1) = "<gif>"        ' key tag in dxl stream
K(1,2) = "</gif>"       ' closing tag in dxl stream
K(1,3) = "gif"          ' file extension
' === Key for any picture converted into gif ===
K(2,1) = "<gif originalformat='notesbitmap'>"   ' key tag in dxl stream
K(2,2) = "</gif>"                               ' closing tag in dxl stream
K(2,3) = "gif"                                  ' file extension
' === Key for JPEGs ===
K(3,1) = "<jpeg>"       ' key tag in dxl stream
K(3,2) = "</jpeg>"      ' closing tag in dxl stream
K(3,3) = "jpg"          ' file extension

' Make sure destination path ends with a \
If Right$(path, 1) = "\" Then
    destinationPath = path
Else
    destinationPath = path & "\"
End If

' Convert document into DXL
dxl = exporter.Export(doc)

' Remove CRs and LFs from DXL
dxl = Replace(dxl, Chr$(13), "")
dxl = Replace(dxl, Chr$(10), "")

' Extract picture data from DXL and write it into tempfile
For i = 1 To 3
    key = K(i,1)
    p1 = InStr(p1+10, dxl, key, 5)
    While p1 > 0
        If p1 > 0 Then
            p2 = InStr(p1, dxl, k(i,2), 5)
            If p2 > 0 Then
                dxlPictureType = K(i,3)
                dxlPicture = Mid$(dxl, p1+Len(key), p2-p1-Len(key))
                
                ' Save DXL into tempfile
                fileNum = FreeFile
                Open destinationPath & "Base64.tmp" For Output As fileNum
                Print #fileNum, dxlPicture
                Close fileNum
                
                ' Create a new Notes Document with embedded picture
                Set doc2 = New NotesDocument(db)
                Set mimeEntity = doc2.CreateMIMEEntity
                Set stream = session.CreateStream
                If Not stream.Open(destinationPath & "Base64.tmp", "binary") Then
                    MessageBox "ExportPictures(): Open tempfile failed"
                    GoTo MyExit
                End If
                
                If stream.Bytes = 0 Then
                    MessageBox "ExportPictures(): Tempfile is empty"
                    GoTo MyExit
                End If
                
                Call mimeEntity.SetContentFromBytes(stream, "image/gif", ENC_BASE64)
                Call stream.Close
                
                On Error Resume Next
                Kill destinationPath & "Base64.tmp"
                On Error GoTo errorHandler
                
                '  Save embedded picture to file
                Set stream = session.CreateStream
                filename = destinationPath & doc.UniversalID & "_" & counter & "." & dxlPictureType
                
                If Not stream.Open(filename, "binary") Then
                    MessageBox "ExportPictures(): Cannot write picture " & filename
                    GoTo MyExit
                End If
                
                Set mimeEntity = doc2.GetMIMEEntity
                Call mimeEntity.GetContentAsBytes(stream)
                Call stream.Close()
                
                fileList(counter) = filename
                
                counter = counter + 1
            End If  ' p2>0
        End If  'p1>0
        
        p1 = InStr(p2+1, dxl, key, 5)
    Wend
Next i

MyExit:
On Error Resume Next
Call stream.Close()
On Error GoTo errorHandler
ExportPictures = fileList
Exit Function

errorHandler:
Print "ExportPictures(): " & Error$ & " in line " &Erl
MessageBox "ExportPictures(): " & Error$ & " in line " &Erl
On Error Resume Next
Kill destinationPath & "Base64.tmp"
Call stream.Close()
On Error GoTo 0
Exit Function
End Function

Upvotes: 0

user784540
user784540

Reputation:

Consider using NotesRichTextNavigator for your rich text field. Obtain the navigator via

Set notesRichTextNavigator  =  notesRichTextItem .CreateNavigator 

Then for notesRichTextNavigator object, use FindFirstElement and FindNextElement calls to examine rich text field contents for particular element types.

Check the navigator class API reference here: https://www.ibm.com/support/knowledgecenter/en/SSVRGU_9.0.1/basic/H_NOTESRICHTEXTNAVIGATOR_CLASS.html


UPDATE

I have checked some things with Notes Designer and I have to say the following.

Navigator approach described above is not suitable to check for pictures pasted to the rich text field. Standard notes functionality does not allow to check whether a rich-text item contains an embedded picture object.

Neither notesDocument.HasEmbedded nor richtextItem.EmbeddedObjects show contained embedded pictures.

But described way is possible to control file attachments, ole objects and document links according to the API specification.

Please note, if you are working with a notesDocument which was not saved, i.e it is a new document, you should call notesUIDocument.Refresh(true) to pass rich text item from front-end UI document to back-end notesDocument. Otherwise getFirstItem(richTextFieldName) will return Nothing.

Upvotes: 4

Related Questions