nicedone
asked on
Lotusscript extract picture from lotus form...
Hi,
I would like to extract screenshots from a lotus form which is a picture on a form...
I am looking for help with the lotusscript code to extract the picture and put it in folder as an attachment,
is it possible?
if yes can you guide me how with the code,
tnx alot
picture to be extracted is in richtext field and looks like something on the form...
fields.JPG
screenshot.JPG
I would like to extract screenshots from a lotus form which is a picture on a form...
I am looking for help with the lotusscript code to extract the picture and put it in folder as an attachment,
is it possible?
if yes can you guide me how with the code,
tnx alot
picture to be extracted is in richtext field and looks like something on the form...
fields.JPG
screenshot.JPG
ASKER
Thank you very much for the code,
but unfortunately on 13th line it decides that it does not have an attachment then it exits and nothing happens,
so i removed that line so that i could continue and try to get "Photo" field
but then it filled rtnav with nothing
what might be wrong?
tnx
but unfortunately on 13th line it decides that it does not have an attachment then it exits and nothing happens,
so i removed that line so that i could continue and try to get "Photo" field
but then it filled rtnav with nothing
what might be wrong?
tnx
try it without line 13 (don't have time to build a test case sorry. you'll have to test...)
alternatively, step through the code with the lotusscript debugger on (Tools:Debug LotusScript)
when you have executed line 14 (Set body = doc.GetFitrstItem("Photo")
check the rbody item for the properties of body.EmbeddedObjects
if that is filled, you can use the ExtractFile method of the EmbeddedObject to save the file to disk. See also designer help: http://publib.boulder.ibm. com/infoce nter/domhe lp/v8r0/to pic/com.ib m.designer .domino.ma in.doc/H_E XTRACTFILE _METHOD.ht ml
alternatively, step through the code with the lotusscript debugger on (Tools:Debug LotusScript)
when you have executed line 14 (Set body = doc.GetFitrstItem("Photo")
check the rbody item for the properties of body.EmbeddedObjects
if that is filled, you can use the ExtractFile method of the EmbeddedObject to save the file to disk. See also designer help: http://publib.boulder.ibm.
ASKER
Sub Initialize
Dim session As NotesSession
Dim db As NotesDatabase
Dim dc As NotesDocumentCollection
Dim doc As NotesDocument
Dim body As NotesRichTextItem
Dim rtnav As NotesRichTextNavigator
Dim att As NotesEmbeddedObject
Set session = New NotesSession
Set db = session.CurrentDatabase
Set dc = db.UnprocessedDocuments
Set doc = dc.GetFirstDocument
'If Not doc.HasEmbedded Then Exit Sub
Set body = doc.GetFirstItem("Photo")
'Set rtnav = body.CreateNavigator
'Dim filepath As String
Set att = body.EmbedObject( EMBED_ATTACHMENT, "","C:/Fatih/jim.sam")
Call att.Extractfile("C:\Fatih\a.jpg")
End Sub
Since I could not retrieve the file i want, I modified the code as above
Although While debugging body is not empty
EmbeddedObject property of body has 0 lenght
thus in the screenshots i provided you can see these values...
why can it transfer it as embeddedobject or attachment somehow
and afterwards the file a.jpg is an empty 0kb file,
any suggestions?
what should i do now? i am stuck here?
body.JPG
body2.JPG
Pure logic.
You create the the attachment by set att=body.EmbedObject(..) call.
The chnages in the rich text are not done when you next call ExtractFile, so nothing is exported. See the Designer help on NotesRichTextItem
The other thing is that i forgot about inline images and the the fact that they are not considered attachments or OLE objects, so not reacheable by conventional LotusScript methods. Sorry I sent you barking up the wrong tree.
It IS possible to do a prgrammatic export, however that plan has several moving parts.
The only way you can get at inline images is if they RichText items are stored as MIME instead of Notes RichText.
1. Make a backup copy of the db to work on.
2. Edit the form design, and mark all the RichText fields to store their contents as HTML and MIME (2nd tab of Field properties)
3. There is a bug when updating, so update the existing documents by code from this IBM technote:
Then use code which extracts the images:
You create the the attachment by set att=body.EmbedObject(..) call.
The chnages in the rich text are not done when you next call ExtractFile, so nothing is exported. See the Designer help on NotesRichTextItem
The other thing is that i forgot about inline images and the the fact that they are not considered attachments or OLE objects, so not reacheable by conventional LotusScript methods. Sorry I sent you barking up the wrong tree.
It IS possible to do a prgrammatic export, however that plan has several moving parts.
The only way you can get at inline images is if they RichText items are stored as MIME instead of Notes RichText.
1. Make a backup copy of the db to work on.
2. Edit the form design, and mark all the RichText fields to store their contents as HTML and MIME (2nd tab of Field properties)
3. There is a bug when updating, so update the existing documents by code from this IBM technote:
Sub Initialize
Dim ws As NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim doc As NotesDocument, docNext As NotesDocument
Dim s As NotesSession
Dim selectedDocs As NotesDocumentCollection
Set s = New NotesSession
Set ws = New NotesUIWorkspace
Set selectedDocs = s.CurrentDatabase.UnprocessedDocuments
Set doc = selectedDocs.GetFirstDocument
Do Until doc Is Nothing
Set docNext = selectedDocs.GetNextDocument(doc)
If Not doc.HasItem("ConvertedMime") Then ' make sure we do this ONCE to avoid bug that deletes images
doc.ReplaceItemValue "ConvertedMime", "1"
doc.Save True, False
Set uidoc = ws.EditDocument(True, doc)
uidoc.Save
uidoc.Close
End If
Set doc = docNext
Loop
End Sub
Then use code which extracts the images:
Dim mEnt As NotesMIMEEntity, mEntNext As NotesMIMEEntity, sImg As NotesStream
Dim pathName$, subType$, filename$
' Note you need to create a meaningful filename here, maybe based on other fields in th doc
filename = doc.SimpleName(0)
Set mEnt = doc.GetMIMEEntity("Photo")
Do
Set mEntnext = mEnt.GetNextEntity
If mEnt.Contenttype = "image" Then
subType = mEnt.ContentSubtype
Set sImg = session.CreateStream
' Note you need to create a meaningful filename here, maybe based on other fields in th doc
pathname = "c:\temp\" & filename & "." & subtype
If Not sImg.Open(pathname, "binary") Then
MsgBox pathname,, "Open failed"
Exit Sub
End If
Call mEnt.GetContentAsBytes(sImg, True)
Call sImg.Close
End If
Set mEnt = mEntNext
Loop Until mEnt Is Nothing
Call doc.CloseMIMEEntities(False, "Photo")
ASKER
Thanks for your assistance,
I get the object variable not set error in the second agent.(the one that extracts the image)
On line 8 and then i commented out this line and tried it for just 1 document with only the Photo richtextitem to be extracted but then I get Object variable not set error on line 9
somehow from this line of code;
Set mEnt = doc.GetMIMEEntity("Photo")
mEnt comes empty :(
what would be your suggestion ? what i am doing wrong...i also put a screenshot of the debugging screen.. thanx in advance for your support...
ment.JPG
I get the object variable not set error in the second agent.(the one that extracts the image)
On line 8 and then i commented out this line and tried it for just 1 document with only the Photo richtextitem to be extracted but then I get Object variable not set error on line 9
somehow from this line of code;
Set mEnt = doc.GetMIMEEntity("Photo")
mEnt comes empty :(
what would be your suggestion ? what i am doing wrong...i also put a screenshot of the debugging screen.. thanx in advance for your support...
ment.JPG
ASKER
Dim mEnt As NotesMIMEEntity, mEntNext As NotesMIMEEntity, sImg As NotesStream
Dim pathName$, subType$, filename$
' Note you need to create a meaningful filename here, maybe based on other fields in th doc
Dim ws As NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim doc As NotesDocument, docNext As NotesDocument
Dim session As NotesSession
Dim selectedDocs As NotesDocumentCollection
Set session = New NotesSession
Set ws = New NotesUIWorkspace
Set selectedDocs = session.CurrentDatabase.UnprocessedDocuments
Set doc = selectedDocs.GetFirstDocument
filename = doc.Form(0)
Set mEnt = doc.GetMIMEEntity("Photo")
Do
'Set mEntnext = mEnt.GetNextEntity
If mEnt.Contenttype = "image" Then
subType = mEnt.ContentSubtype
Set sImg = session.CreateStream
' Note you need to create a meaningful filename here, maybe based on other fields in th doc
pathname = "c:\temp\" & filename & "." & subtype
If Not sImg.Open(pathname, "binary") Then
MsgBox pathname,, "Open failed"
Exit Sub
End If
Call mEnt.GetContentAsBytes(sImg, True)
Call sImg.Close
End If
Set mEnt = mEntNext
Loop Until mEnt Is Nothing
Call doc.CloseMIMEEntities(False, "Photo")
Here is the code in the second agent if you want to look at the code too...
thanks for your help
For this to work, the form definition of the document (not the Form name, but the design) needs to correct, i.e. the property 'Store contents as HTML and MIME' needs to be checked. AND the documents has to be opened in edit mode and saved, so the field will be converted from rich text to MIME.
You can check the design is correct and conversion has occurred by pointing to the document you are using to check the agent, ands opening the property box. Check the fields tab of the Document properties, scroll down to the Photo field,and click on it.
The first two lines in the righthand part should read:
Another point is that setting the filename to the form will allow you to export exactly one photo 'PerData.jpg'. Please use your imagination and create a filename which will be unique even if you run the agent on many documents.
modded code cheking tha availability of Photo:
You can check the design is correct and conversion has occurred by pointing to the document you are using to check the agent, ands opening the property box. Check the fields tab of the Document properties, scroll down to the Photo field,and click on it.
The first two lines in the righthand part should read:
[Field Name: Photo
Data Type: MIME Part
If it reads
Field Name: Photo
Data Type: Rich Text
, the design was not changed, or the document not re-saved.Another point is that setting the filename to the form will allow you to export exactly one photo 'PerData.jpg'. Please use your imagination and create a filename which will be unique even if you run the agent on many documents.
modded code cheking tha availability of Photo:
Dim mEnt As NotesMIMEEntity, mEntNext As NotesMIMEEntity, sImg As NotesStream
Dim pathName$, subType$, filename$, v as Variant
' Note you need to create a meaningful filename here, maybe based on other fields in th doc
Dim ws As NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim doc As NotesDocument, docNext As NotesDocument
Dim session As NotesSession
Dim selectedDocs As NotesDocumentCollection
Set session = New NotesSession
Set ws = New NotesUIWorkspace
Set selectedDocs = session.CurrentDatabase.UnprocessedDocuments
Set doc = selectedDocs.GetFirstDocument
Do Until doc Is Nothing
' get next document before, because this might fail if we save or delete doc
Set docNext = selectedDocs.GetNextDocument(doc)
' need to set this to a unique recognizable name
' consider the shortname or employee number
' this example combines the form name and a Unique identifier
v = Evaluate("@Unique")
filename = doc.Form(0) & "-" & v(0)
Set mEnt = doc.GetMIMEEntity("Photo") ' try to get Photo MIME
If mEnt Is Nothing Then
Print "No 'Photo' in doc: "; doc.UniversalID
Else
Do
'Set mEntnext = mEnt.GetNextEntity
If mEnt.Contenttype = "image" Then
subType = mEnt.ContentSubtype
Set sImg = session.CreateStream
' Note you need to create a meaningful filename here, maybe based on other fields in th doc
pathname = "c:\temp\" & filename & "." & subtype
If Not sImg.Open(pathname, "binary") Then
MsgBox pathname,, "Open failed"
Exit Sub
End If
Call mEnt.GetContentAsBytes(sImg, True)
Call sImg.Close
End If
Set mEnt = mEntNext
Loop Until mEnt Is Nothing
Call doc.CloseMIMEEntities(False, "Photo") ' clean up after ourselves
End If
Set doc = docNext ' point doc to next document
Loop
ASKER
Hi,
Thank you , when I do the first step you mention..
1) Save that richtextitem field ,check the property 'Store contents as HTML and MIME'
2) edit and save document(document refresh)
after that when i check the Photo field i see that there are 4 Photo fields rather then 1...
i attach the all 4 Photo item contents for you to check, what am i doing wrong here?
1photo.JPG
2photo.JPG
3Photo.JPG
4photo.JPG
Thank you , when I do the first step you mention..
1) Save that richtextitem field ,check the property 'Store contents as HTML and MIME'
2) edit and save document(document refresh)
after that when i check the Photo field i see that there are 4 Photo fields rather then 1...
i attach the all 4 Photo item contents for you to check, what am i doing wrong here?
1photo.JPG
2photo.JPG
3Photo.JPG
4photo.JPG
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
tnx.sorry for the delay I was not able to test it since we had a health problem in the family..
Open in new window