Trapping background image size

our users would like us to switch on the allows users to change background facility - which I am prepared to do only as long as I can control the size of images that they use as background

can this be done ?

thanks

Paul

Subject: RE: trapping background image size

I assume you mean size in bytes, not dimensions.

The action of setting the background of a document to an imported image, creates an item called $BackgroundBody. Probably, in the Querysave event you can detect that NotesItem and test its ValueLength property.

If you’re concerned that these images might take up too much space, why not supply several backgrounds as image resources? These use very little extra space each time they’re used, and they’re less trouble for the users than seeking out and importing their own backgrounds. Providing you name them so that they’re grouped together at the top of the selection list, before any other images you use in your application.

Subject: RE: trapping background image size

I have put this code into the querysave event and it works but only once the document has already been saved. Is there a way to amend it so that the document can’t be saved if the background is too big ?

Thanks

Paul

Sub Querysave(Source As Notesuidocument, Continue As Variant)

Dim workspace As New NotesUIWorkspace

Dim uidoc As NotesUIDocument

Set uidoc = workspace.CurrentDocument

Dim doc As notesdocument

Set doc = uidoc.Document

Dim item As notesitem

If doc.HasItem("$Background") Or doc.HasItem("$BackgroundR5") Then

	If doc.HasItem("$Background") Then

		Set item = doc.GetFirstItem("$Background")

		Msgbox(item.ValueLength)

	End If

	If doc.HasItem("$BackgroundR5") Then

		Set item = doc.GetFirstItem("$BackgroundR5")

		Msgbox(item.ValueLength)

	End If

End If

End Sub

Subject: RE: trapping background image size

Hm, looks like the $Background field is not assigned until after Querysave executes.

I guess you could test for it in the Postsave instead, but by then it’s too late to just abort the save. You could, however, remove the item and re-save the document (using NotesDocument.Save, not NotesUIDocument.Save).

I suspect if you could do a “trial” save wth SaveOptions = “0”, that would create the $Background item. Then you could remove the SaveOptions and save for real if you still want to.

Subject: Set: Continue = False i.e.

Blen = 0	If doc.HasItem("$Background") Or doc.HasItem("$BackgroundR5") Then

	If doc.HasItem("$Background") Then

		Set item = doc.GetFirstItem("$Background")

		Blen = item.ValueLength

	End If

	If doc.HasItem("$BackgroundR5") Then

		Set item = doc.GetFirstItem("$BackgroundR5")

		Blen = item.ValueLength

	End If

End If

If Blen > 10000 Then

	Msgbox "Background too big"

	Continue = False

End If