Thursday, September 07, 2006

Export inline Notes pictures to disk as GIF files

Have you tried to export an inline picture from Notes database to hard drive? You can of course select the picture, copy it to clipboard, paste it to Paintbrush and then save the new picture to disk. But what if there are more than thousand pictures to process? The manual procedure would take several hours.
Fortunately you can programmatically export pictures using Notes DXL classes. The code below takes the first picture in a richtext field named PictureRT and saves it to disk as a GIF file.

The code uses a LotusScript library for BASE64 decoding, which you can download from Julian Robichaux's web site: http://www.nsftools.com/tips/NotesTips.htm#lsencryption

Example does not use Notes classes for handling XML (NotesDOMParser), it parses the string using it's own logic. In many cases NotesDOMParser processing is to prefer, and I might later create a version which uses NotesDOMParser.

Option Public
Use "base64encdec"

Sub Initialize
Dim session as New NotesSession
Dim db as NotesDatabase
Dim doc as NotesDocument
Dim picdata As String
Dim decstr As String

set db=session.CurrentDatabase
set doc=db.GetDocumentByUNID("1EC1508B08428D4385256E00004B0D3F")

Set exporter = session.CreateDXLExporter
exporter.ConvertNotesBitmapsToGIF = True
out = exporter.Export(pdoc)

find1="<item name='PersonPicture'"
find2="</item>"
findpic1="<picture"
findpic2="</picture>"
rtstart=Instr(out, find1)
rtstart2=Instr(rtstart, out, findpic1)
rtfinish2=Instr(rtstart2, out, findpic2)
purepic= Mid(out, rtstart2, rtfinish2-rtstart2+Len(findpic2))


finddata1="<gif originalformat="'notesbitmap'">"
finddata2="</gif>"
picdatastart=Instr(purepic, finddata1)
picdatafinish=Instr(picdatastart, purepic, finddata2)
picdata=Mid(purepic, picdatastart+Len(finddata1), picdatafinish-picdatastart-Len(finddata2))

decstr=DecodeBase64(picdata)
fout = Freefile
Open "c:\testgif.gif" For Output As fout
Print #fout, decstr
Close #fout
End Sub

4 comments:

Anonymous said...

Very nice and helpful! Thanks!

Anonymous said...

Nice! Thanks for the example.

Anonymous said...

Can it work with notes R5?

Simatupang said...

http://www.deusdoceu.com/
http://www.onenightymedia.com/
http://www.listadicibo.web.id/
http://www.pkercollection.com/
https://www.carabermainpokerr.info/