Notes RTF域添加图片

    CS结构,最开始的需求是用户在填完报销单的时候需要把单子打印出来附上Hard copy交到财务,由于财务每天要处理很多单子和Hard copy,如果手工输入报销单号码会非常不便,也很耗时间,他们希望能加上一个二维码,拿到Hard copy后用扫描枪一扫就可以了。虽然后来这个系统转交给了另一位同事,但是我一直在思考这个问题怎么解决,曾经试过嵌入ActiveX控件或Applet等的方法,但都不是太完美。我同事的解决方案是使用专用的条形码字体,但是需要在每台客户端安装这种字体。最近我终于找到了我的解决方法,支持各种条码。

 
  注:这个实例只是添加图片部分,二维码部分可以使用Google zxing包,Notes实例可见我的另一篇博文。代码需要微调一下,由于我是做测试用的,UI部分是我自己的解决方案,Function EmbedPictureIntoRichText(doc As NotesDocument, strFilePath As String) As Boolean出自 http://www.grange.com.br/blog/40-lotus/499-lotusscript-code-to-embed-a-picture-into-a-notes-richtext-item
 
 
  
  
  
  
  1. '我要的效果是在当前打开的文档中插入一张图片,并打印。不需要用户自己去选择图片,也不能让用户去修改RTF字段 
  2. Sub Click(Source As Button) 
  3.  
  4.     Dim ws As New NotesUIWorkspace 
  5.     Dim uidoc As NotesUIDocument, readuidoc As NotesUIDocument 
  6.     Dim doc As Notesocument 
  7.     Dim session As New NotesSession 
  8.  
  9.     Set uidoc = ws.CurrentDocument 
  10.     '这种方法也可以,但是RTF域必须是编辑状态 
  11.     'uidoc.GotoField("aa") 
  12.     'Call uidoc.Import("JPEG Image", "C:\\aa.jpg") 
  13.     'uidoc.EditMode = False 
  14.  
  15.     ’我的方法 
  16.     Set doc = uidoc.Document 
  17.     '先保存当前文档 
  18.     uidoc.Save 
  19.     '置为阅读模式 
  20.     uidoc.EditMode=False 
  21.     '在后台文档中添加RTF的图片 
  22.     Call EmbedPictureIntoRichText(doc, "C:\aa.jpg"
  23.     ’在CS下以阅读模式打开新的UI文档实例 
  24.     Set readuidoc = ws.EditDocument(False, doc,True,""True,True ) 
  25.     '关闭原来的UI文档 
  26.     uidoc.Close 
  27.     '打印 
  28.     readuidoc.Print 
  29. End Sub 
  30. Function EmbedPictureIntoRichText(doc As NotesDocument, strFilePath As StringAs Boolean 
  31.     On Error Goto errorHandle 
  32.     EmbedPictureIntoRichText = False 
  33.  
  34.     Dim session As New NotesSession 
  35.     Dim db As NotesDatabase 
  36.     Dim body As NotesMIMEEntity 
  37.     Dim header As NotesMIMEHeader 
  38.     Dim child As NotesMIMEEntity 
  39.     Dim stream As NotesStream 
  40.     Dim fileFormat As String 
  41.     Dim rtitemA As NotesRichTextItem 
  42.     Dim rtitemB As NotesRichTextItem 
  43.  
  44.     Set db = doc.Parentdatabase 
  45.     Set stream = session.CreateStream 
  46.     Call stream.Open(strFilePath)  
  47.     Set rtitemB = doc.GetFirstItem("DummyRichText"
  48.     If Not rtitemB Is Nothing Then 
  49.     Call rtitemB.Remove() 
  50.     End If 
  51.     Set body = doc.CreateMIMEEntity("DummyRichText")  
  52.     Set header = body.CreateHeader("Content-Type")  
  53.     Call header.SetHeaderVal("multipart/mixed"
  54.     Set child = body.CreateChildEntity() 'Set childEntity = richTextItemObj.CreateChildEntity() 
  55.     fileFormat = "image/jpeg" 'Other formats are "image/gif" "image/bmp" 
  56.     Call child.Setcontentfrombytes(stream, fileFormat, 1730)  
  57.     Call stream.Close()  
  58.     Call doc.save(FalseFalse'JUST TO REFRESH 
  59.  
  60.     Set rtitemA = doc.GetFirstItem("aa"
  61.     Set rtitemB = doc.GetFirstItem("DummyRichText"
  62.     Call rtitemA.AppendRTItem( rtitemB ) 
  63.     Call rtitemB.Remove() 
  64.     Call doc.save(FalseFalse
  65.  
  66.     EmbedPictureIntoRichText = True 
  67.     Exit Function 
  68.     errorHandle: 
  69.     Msgbox Cstr(Erl) & ": " & Error 
  70. End Function 

 

你可能感兴趣的:(图片,Lotus,RFT,notes)