1

我有一些 NotesDocument,其中一些 RichText 字段同时具有文本和内联图像。我可以获取该项目的文本部分,但无法使用 lotusscript 检索内联图像。任何人都可以建议我一种从该文档中检索内联图像的方法。莲花脚本代码:

Sub Click(Source As Button)
    Dim session As New NotesSession   
    Dim db As NotesDatabase   
    Dim mainDoc As NotesDocument
    Dim v As NotesView   
    Set db = session.CurrentDatabase   

    Dim fileName As String
    Dim fileNum As Integer
    fileNum% = Freefile()
    fileName$ = "D:\data.txt"
    Open FileName$ For Append As fileNum%

    Set v = db.GetView("MyView")
    Set mainDoc = v.GetFirstDocument       

    While Not ( mainDoc Is Nothing )              
        Forall i In mainDoc.Items
            If i.Type = RICHTEXT Then
                 Write #fileNum% ,    i.Name & ":" & i.text  'how the images??
            End If
        End Forall              
        Set mainDoc = v.GetNextDocument( mainDoc )  
    Wend
End Sub

谢谢。

4

4 回答 4

3

Midas 是最简单的方法,但它不是免费的。(这比节省的总时间更值得,但是如果您的组织与我工作过的组织类似,那么该工具的全部成本将被强加给拥有当前项目的计费单位,而不是而不是将其摊销到整个组织,并且他们可能会在同意成本之前更改他们的要求。)还有另一种方法,那就是使用导出选项 ConvertNotesBitmapToGIF 将数据库导出到 DXL (Domino XML)。图像将在 XML 中显示为<picture>具有 Base64 编码数据的元素。如果您完全在 Notes 环境中操作,则需要创建一个临时文档,其中包含用作 NotesMIMEEntity 的富文本字段,以便在将编码图片流式传输到文件之前将其转换为二进制文件(使用 NotesStream)。所有这些都假设您使用的是版本 6 或更高版本;如果您使用 R5 或更早版本,Midas 或使用 C API 直接访问 CD 记录是唯一的飞行方式。

于 2010-11-08T07:11:48.357 回答
1

七年后,我一直在把头发拉出来。Rod H 的答案是附件,但嵌入图像完全是另一回事。

我最好的运气来自@andre-guirard 的 LotusScript Gold Collection 代码,位于此处:https ://www.openntf.org/main.nsf/project.xsp?r=project/LotusScript%20Gold%20Collection 但是,这并没有一切,因为它不处理嵌入图像以旧方式嵌入的文档。(Notes 改变了它存储嵌入图像的方式。)

我非常努力地将它与此处提供的 AGECOM 信息相结合:https ://www.agecom.com.au/support/agecomkb.nsf/0/58cbf10f0ab723c9ca25803e006c7de8?OpenDocument通过更改 Andre 的 EmbeddedImage 对象以通过查看来无缝处理这两种格式如果富文本字段中的嵌入图像实际上只是指向 $FILE 字段的指针,然后,如果是这样,则获取 FileItem 对象,但最终我用尽了我的理解和选择,以至于我无法证明花费我雇主的钱是合理的资源(我的时间)就可以了。

因此,如果您嵌入的图像都包含在新的方式中,我认为 Andre 的代码将不会受到干扰。否则,我尽了最大努力,但我没有答案......我有什么(对我来说)死胡同,希望你或其他偶然发现它的人可以通过解释我是什么来让我尴尬做错了!

基本上,我从 Andre 的代码开始,并通过以下方式对其进行了更改...

在 DOMUtils 中,添加以下方法:

%REM
    Function DU_GetMeOrNextSiblingWithAttr
    Description: Starting with a particular node, return that node or the next sibling with an attribute that has a particular value.
        Does not recurse into the tree; looks only at the node passed and later siblings. 
    Parameters:
        nodeStart: node to start your search with.
        targetElement: element name of desired node.
        attrName: attribute name you want to check.
        attrValue: attribute value of element you're looking for.
        flags: string-matching flags to compare attribute, e.g. 1 for case insensitive.
%END REM
Function DU_GetMeOrNextSiblingWithAttr(nodeStart As NotesDOMNode, ByVal targetElement$, ByVal attrName$, ByVal attrValue$, ByVal flags%) As NotesDOMElementNode
    Dim node As NotesDOMNode, elTmp As NotesDOMElementNode
    Set node = nodeStart
    Do Until node.Isnull
        If node.Nodetype = DOMNODETYPE_ELEMENT_NODE Then
            If node.Nodename = targetElement Then
                Set elTmp = node
                If StrComp(elTmp.Getattribute(attrName), attrValue, flags) = 0 Then
                    Set DU_GetMeOrNextSiblingWithAttr = elTmp
                    Exit Function
                End If
            End If
        End If
        Set node = node.Nextsibling
    Loop
End Function

将 FileItem.New 替换为以下代码:

    %REM
    Sub New
    Description: Arguments are the parsed DOM node of the element representing a
        design element, and the name of the composite item you would like to read,
        modify or create.
%END REM
Sub New(parent As FileItemParent, elNote As NotesDOMElementNode, itemName$, fileName$)
    Set m_elNote = elNote
    
    SetItem elNote, itemName$, fileName$
    

    Dim node As NotesDOMNode
    Set node = m_elNote.Parentnode
    While node.Nodetype <> DOMNODETYPE_DOCUMENT_NODE
        Set node = node.Parentnode
    Wend
    Set m_domd = node
    parent.RegisterFileItem Me ' make sure the design element knows about us.
        ' (in case someone gets smart and invokes the constructor directly
        ' instead of using the nice methods we've provided).
End Sub

%REM
    Sub SetItem
<!-- Created Dec 6, 2017 by JSmart523 -->
    If fileName$ is blank, returns the XPath equivalent of elNote/ancestor::document/item[@name=itemName$][position()=1]
    If fileName$ is not blank, returns the XPath equivalent of elNote/ancestor::document/item[@name=itemName$][object/file/@name=fileName$][position()=1]
    
    Case insensitive. Changes itemName$ and fileName$ to the correct case if found.

    Also sets Me.m_elItem to the returned NotesDOMElementNode
    Also sets Me.m_elRawData to the file contents
%END REM
Sub SetItem(elNote As NotesDOMElementNode, itemName$, fileName$)
    Dim elFile As NotesDOMElementNode
    Dim node As NotesDOMNode
    
    'set node to ancestor::document
    Set node = elNote
    Do Until node.NodeName = "document"
        Set node = node.ParentNode
    Loop
    
    'If fileName$ = "", get the first ancestor::document/item[@name=itemName$]
    'Otherwise,         get the first ancestor::document/item[@name=itemName$][/object/file/@name=fileName$]
    Set m_elItem = DU_GetChildOfType(node, DOMNODETYPE_ELEMENT_NODE)
    QualifyingItem m_elItem, itemName$, m_elRawData, fileName$
    m_itemName = itemName$
    m_fileName = fileName$
End Sub

%REM
    Sub QualifyingItem
<!-- Created Dec 8, 2017 by JSmart523 -->
    Starting with incoming elItem node, ensures it's an item we want or changes elItem to the first sibling that qualifies.
%END REM
Sub QualifyingItem(elItem As NotesDOMElementNode, itemName$, elRawData As NotesDOMElementNode, fileName$)
    Dim elFile As NotesDOMElementNode
    Dim node As NotesDOMNode
    Dim elObject As NotesDOMElementNode

    If Not elItem Is Nothing Then
        'Initially, elItem is just a starting point, not necessarily the item we want.
        'If it's an item with the right name, great, otherwise change elItem to the next sibling item with the right name. 
        Set elItem = DU_GetMeOrNextSiblingWithAttr(elItem, "item", "name", itemName$, 1)
        
        If Not elItem Is Nothing Then
            If fileName$ = "" Then
                'we have the right item, and aren't looking for a file node, which means we want the rawitemdata node
                Set elRawData = DU_getChildNamed("rawitemdata", elItem)
            Else
                'We are looking for a $FILE item that contains a file.
                'There are possibly several $FILE items within a document, one for each file. We've got the right one if ./object/file/@name = fileName$
                Do
                    Set elObject = DU_GetChildNamed("object", elItem)
                    If Not elObject Is Nothing Then
                        Set elFile = DU_GetChildWithAttr(elObject, "file", "name", fileName$, 1)
                        If Not elFile Is Nothing Then
                            'Yay! We have the right elItem node!
                            Set elRawData = DU_GetChildNamed("filedata", elFile)
                            fileName$ = elFile.GetAttribute("name")
                            Exit Do
                        End If
                    End If
                    Set elItem = DU_GetMeOrNextSiblingWithAttr(elItem.NextSibling, "item", "name", itemName$, 1)
                Loop Until elItem Is Nothing
                'At this point, either we jumped out of the loop with a valid elItem and elRawData, or elItem is Nothing
            End If
        End If
    End If
    
    If elItem Is Nothing Then
        'we didn't find the correct item
        'make sure elRawData is changed to Nothing, too.
        Set elRawData = Nothing
    Else
        itemName$ = elItem.GetAttribute("name")
    End If
End Sub

同样在 FileItem 脚本库中,添加一个新类 FileItemParent

    %REM
    Class FileItemParent
<!-- Created Dec 5, 2017 by JSmart523 -->
    This is a base class for objects that use FileItem objects
%END REM
Class FileItemParent
    m_elElRoot As NotesDOMElementNode
    m_elFD As NotesDOMElementNode
    Public m_fileItem As FileItem
    m_fItems List As FileItem ' list of FileItems we've created and returned to caller.
    m_iMode As Integer

    %REM
        Property Get DOMElement
        Description: Return the element node representing the design element.
    %END REM
    Public Property Get DOMElement As NotesDOMElementNode
        Set DOMElement = m_elElRoot
    End Property

    %REM
        Sub New
        Arguments:
            db: the database containing the design element.
            elElement: the DOM element corresponding to the design note (e.g. the <note>
                element).
            domp: The DOM parser object containing elElement.
    %END REM
    Sub New(elElement As NotesDOMElementNode)
        Set m_elElRoot = elElement
    End Sub
    
    Sub Delete
        On Error Resume Next
        ForAll thing In m_fItems
            Delete thing
        End ForAll
    End Sub
    
    %REM
        Function HasItem
        Description: Determine whether there's an item element in the note DXL with a
            given item name.
            Note that the presence of an item doesn't guarantee it's formatted as a file
            CD record.
    %END REM
    Function HasItem(ByVal itemName$) As Boolean
        HasItem = Not (DU_GetChildWithAttr(m_elElRoot, "item", "name", itemName, 1) Is Nothing)
    End Function

    
    %REM
        Function RegisterFileItem
        Description: For internal use -- lets the FileItem class notify us that it's
            referencing our DOM tree so that we can delete the object if we erase the
            corresponding item element.
    %END REM
    Sub RegisterFileItem(x As FileItem)
        Set m_fItems(LCase(x.itemName)) = x
        If m_FileItem Is Nothing Then
            Set m_FileItem = x
        End If
    End Sub
    
    %REM
        Function GetFileItem
        Description: Retrieve the FileItem object associated with a CD-record item.
            An object will be returned even if the item doesn't exist, which you can
            use to create the item via UpdateFile method.
    %END REM
    Function GetFileItem(itemName$, fileName$) As FileItem
        Set GetFileItem = New FileItem(Me, m_elElRoot, itemName, fileName)
    End Function
    
End Class

FileItemParent 类主要是取自 Andre 的 FileResource 类的代码,以便 FileResource 和 EmbeddedImage 都可以使用它。更改 FileResource 以扩展 FileItemParent,删除所有重复的代码。

现在我们要更改 EmbeddedImage,以便即使嵌入的图像节点包含指向 $FILE 项的链接而不是实际内容,也返回实际内容。

因此,更改 EmbeddedImage 以扩展 FileItemParent

将以下方法添加/替换到 EmbededImage

%REM
    Sub InitFileItem
<!-- Created Dec 6, 2017 by JSmart523 -->
    Called by New
%END REM
Sub InitFileItem()
    Dim buffer As Variant 'byte array
    Dim iFileNameLen As Integer
    Dim sFileName As String
    Dim sItemName As String
    Dim stream As NotesStream
    
    If Len(m_b64) < 30000 Then
        'If content is short then maybe it's a link to a $FILE item instead of the actual content?
        Dim session As New NotesSession
        Set stream = session.CreateStream()
        Base64ToBinary m_b64, stream
        stream.Position = 0
        buffer = stream.Read(1)
        If buffer(0) = 196 Then
            'this is a link to a $FILE, not the actual image contents!
            
            stream.Position = 10
            buffer = stream.Read(2)
            iFileNameLen = ConvertWordByteArray(buffer)
            
            stream.Position = 24
            buffer = stream.Read(iFileNameLen)
            sFileName = BytesToString(buffer)
            sItemName = "$FILE"
            
            GetFileItem sItemName, sFileName 'sets m_fileItem to a FileItem object
        End If
    End If
End Sub

%REM
    Property Get SuggestedFileName
%END REM
Public Property Get SuggestedFileName As String
    If m_fileItem Is Nothing Then
        SuggestedFileName = "Embedded-" + ItemName + "." + SuggestedFileType
    Else
        SuggestedFileName = m_fileItem.FileName
        If InStr(SuggestedFileName, ".") = 0 Then
            SuggestedFileName = SuggestedFileName + "." + SuggestedFileType
        End If
    End If
End Property

%REM
    Property Get SuggestedFileType
%END REM
Public Property Get SuggestedFileType As String
    If ImageType = "notesbitmap" Then
        SuggestedFileType = "bmp"
    Else
        SuggestedFileType = ImageType
    End If
End Property

%REM
    Sub ReadFileToStream
%END REM
Sub ReadFileToStream(streamOut As NotesStream)
    If m_FileItem Is Nothing Then
        ReadToStream streamOut
    Else
        Set m_FileItem.Stream = streamOut
        m_FileItem.Load
    End If
End Sub

然后将 EmbeddedItem.New 更改为最后调用 InitFileItem ,这样如果它是一个链接,那么获取内容将返回内容而不是链接。

好的,据我所知,到目前为止一切都很好,但问题是存储在 $FILE 项目中的嵌入图像的 CD 记录(即富文本字段的嵌入图像节点仅包含一个链接而不是实际图像)已记录在案尽管有 AGECOM 的代码和解释,但对我来说,这种方式是难以理解的。我可以使用上面的代码和 Andre 的 EmbeddedImageList 对象来抓取每个嵌入的图像,但我根本无法让“ConvertOldCDToNew”方法正常工作,所以我无法将旧的 CD 记录格式转换为可靠的、未损坏的文件!我不知道我是否剥离了太多字节,没有剥离正确的字节,或者我只是忘了携带两个

于 2018-01-22T21:59:33.903 回答
0

我建议您查看 Genii Software MidasLSX 产品。他们提供了一个 LotusScript 扩展包,可以更轻松地处理 Lotus Notes Rich Text 项目的复杂性。

http://www.geniisoft.com/showcase.nsf/MidasHelp

否则,您可以尝试使用 NotesRichTextNavigator 类来访问富文本项中的图像(理论上)。关于这类事情的文档很少。我无法完全确定使用该类的图像会显示什么,但假设您浏览富文本项并能够将图像作为 NotesEmbeddedObject 处理,我知道有一种方法可以将对象保存到磁盘那堂课。

另一个(疯狂的)想法是通过电子邮件发送文档,并让另一个可以更轻松地处理电子邮件正文的程序接收它。Notes 对处理自己的富文本字段帮助不大。

于 2010-10-25T15:23:50.170 回答
-1

这是我用来从文档上的富文本字段中分离文件的代理。

Option Public
Dim uidoc As notesuidocument
Dim doc As NotesDocument
Dim db As NotesDatabase
Dim obj As NotesEmbeddedObject
Dim collection As NotesDocumentCollection
Dim rt As Variant
Dim attachNames As Variant
Dim i As Integer, x As Integer
Dim j As Integer
' Agent  - Detach Attachments to C drive for later reattachment
' Copies all attachment in richtext field to personal directory.

Sub Initialize
    Dim ws As New notesuiworkspace
    Dim ses As New NotesSession
    Set db = ses.CurrentDatabase
    Set collection = db.UnprocessedDocuments
    '  get first doc in collection
    For j = 1 To collection.Count
        Set doc = collection.GetNthDocument( j )    
' ---  create array of filenames of all the attachments in the document
        i = 0
        Redim attachNames(i)
        Forall x In doc.items
            If x.name = "$FILE" Then
                attachNames(i) = x.values(0)
                i = i + 1
                Redim Preserve attachNames(i)
            End If
        End Forall

        If i > 0 Then
            Redim Preserve attachNames(i-1)
        End If

' ---  for all of the filenames in attachNames, if it exists in the rich text field, detatch them
        If doc.hasItem("richtextfieldname") Then
            Set rt = doc.GetFirstItem("richtextfieldname")
        End If
        If attachNames(0) <> "" Then
            Forall x In attachNames 
                Set obj = rt.GetEmbeddedObject( x )
                If Not( obj Is Nothing ) Then
                    Call obj.ExtractFile( "C:\path\" & Cstr(x) )
                End If
            End Forall
        End If
        Call doc.save(True, False)
    Next
End Sub
于 2012-12-05T22:39:52.753 回答