In-line images: remove or prevent

A client has a Notes correspondence database used for broadcasting email to customers. Lately they’ve been augmenting simple text messages with in-line images. Often, they pay no heed to the source image size nor the result and end up with embedding 1 meg or larger images. The database is quickly growing huge.

  1. Is there a way to strip all the images from documents using Lotus Script? Once the messages are sent, they want to preserve the fact that it was sent, but don’t need to preserve the images.

  2. Is there a way to prevent the document from saving if the image they are using exceeds a certain size?

Thanks.

Subject: In-line images: remove SOLUTION

This agent works on selected documents and removes all in-line images (embedded pictures), leaving everything else unchanged.

(Declarations)

Dim domParser As NotesDOMParser

Dim exporter As NotesDXLExporter

Dim importer As NotesDXLImporter

Sub Initialize

	Dim session As New NotesSession

Dim db As NotesDatabase

Set db = session.CurrentDatabase



Dim dc As NotesDocumentCollection

Set dc = db.UnprocessedDocuments



Dim doc As NotesDocument





Set exporter = session.CreateDXLExporter

Set domParser=session.CreateDOMParser

Set importer = session.CreateDXLImporter ( domParser, db )

importer.DocumentImportOption = DXLIMPORTOPTION_REPLACE_ELSE_IGNORE



Set doc = dc.GetFirstDocument

While Not(doc Is Nothing)	

	Call exporter.SetInput ( doc )

	Call exporter.SetOutput ( domParser )

	Call domParser.SetOutput ( importer )

	On Event PostDOMParse From domParser Call RemovePics

	Call exporter.process

	Set doc = dc.GetNextDocument(doc)

Wend

End Sub

Sub RemovePics(Source As NotesDOMParser)

Dim i As Integer

Dim rootElement As NotesDOMElementNode

Dim docList As NotesDOMNodeList

Dim node As NotesDOMNode

Dim parentnode As notesDOMNode, parnode As notesDOMNode



Set rootElement = domParser.Document.DocumentElement

Set docList = rootElement.GetElementsByTagName ( "picture" )



If docList.NumberOfEntries = 0 Then : Exit Sub



For i = 1 To docList.NumberOfEntries

	Set node = docList.GetItem(1)

	Call RemoveAllDescendants (node) 'Not sure this is necessary, but why not be thorough?

	Set parentNode = Node.ParentNode

	Set parnode = parentNode.RemoveChild( node )

	Set docList = rootElement.GetElementsByTagName ( "picture" )

Next

Call Source.Serialize

End Sub

Sub RemoveAllDescendants(inNode As NotesDOMNode)

If inNode.HasChildNodes Then

	Dim currentChild As NotesDOMNode

	Dim nextChild As NotesDOMNode

	Set currentChild = inNode.FirstChild

	Do Until currentChild.IsNull

		Set nextChild = currentChild.NextSibling

		If currentChild.HasChildNodes Then

			Call RemoveAllDescendants(currentChild)

		Else

			Call inNode.RemoveChild(currentChild)

		End If

		Set currentChild = nextChild

	Loop

End If

End Sub

Subject: It works!

It works! Great! Thanks a lot!

Subject: In-line images: remove or prevent

I assume inline images act as embedded objects? If so you can work with a script that checks the size of the embedded object and stop the save, hmmm thinking ahead of myself now…can you actually check it before it is saved?

Am sure you can create a work around :slight_smile:

Subject: RE: In-line images: remove or prevent

If you can get a handle on the NotesEmbeddedObject, you can do this. I’m thinking through NotesRichTextItem.GetEmbeddedObject? Not sure.

Once you have a handle on the NotesEmbeddedObject there is a property called FileSize. If the FileSize exceeds a certain size, use the Remove method of NotesEmbeddedObject to remove the image.

Good luck.

Subject: RE: In-line images: remove or prevent

Thanks for the responses, but I already know in general what needs to be done. I’ve experimented some in the obvious directions, but with no success. GetEmbeddedObject, as you know, requires the text name of the object, which in-line images do not possess.

It seems like such a simple pursuit, but the solution is eluding me. Can anyone else suggest a course to pursue?

Subject: RE: In-line images: remove or prevent

You can remove the image after saving using DXL (or the C API or a third-party tool that “brokers” the C API for you, like the Midas Rich Text LSX). If you use DXL, all you need to do is remove any picture nodes you find, and perhaps replace them with a deletion notice. The Designer Help for NotesDXLExporter, NotesDXLImporter and NotesDOMParser have good examples, and you can export a test document to a file (using a NotesStream) to examine the XML you will be working with. The process is pretty straightforward – very similar to what you’d do in JavaScript to manipulate a web page.

Subject: RE: In-line images: remove or prevent

Thank you, Stan. I had seen some references to this technique in similar posts, but I have never worked with DXL and was hoping to find something more familiar. Lazy me! But it looks like this is the obvious avenue of pursuit, so I’m going to get started right away. I will post my results in this thread when I come up with working code.

Subject: RE: In-line images: remove or prevent