Link to home
Start Free TrialLog in
Avatar of amp834
amp834

asked on

Lotus Notes "Expand All Sections" for printing

I have a Lotus Notes script that opens a .nsf file, chooses a document, and prints it.  If there is a section that is collapsed, it should be expanded before printing.

Does anyone know how to expand the section for printing?  I have tried calling a function that supposedly does this, but the results do not come out.  Is there some setting or other info I have to watch out for?
Avatar of SysExpert
SysExpert
Flag of Israel image

Please post code.

Options include using the sendkeys funtionality to do this via the UI ( keyboard emulation ).

 
I hope this helps !
If you have access to the .nsf file code then you can just change section properties using Designer to auto-expand section when printed.
Avatar of amp834
amp834

ASKER

SysExpert and fgrushevsky, thanks for the responses.  Can you elaborate?

Here is part of the code:

			Dim doc As NotesDocument
			On Error Goto PrintErr1
			Set doc = db.GetDocumentByUNID(strArg)
			If (doc Is Nothing) Then
				strRet="Error: could not open specified email item"
				Goto RequestDone
			End If
			Set uidoc = workspace.EditDocument(False,doc,True)	
			Call uidoc.print(1,,,False)
			Doevents
			Call uidoc.Close
			Doevents

Open in new window

Do you have designer rights to the database that contains documents that you print?
Do you have access to the design of the document (well, to the form that is used by your document) that you open and print?
If so, open this database in Designer, find the form that is used for this document, within the form find section that you want to adjust. Right click on the section, go to the section properties, go to the second tab (expand and collapse)  and set auto-expand when printed
Avatar of amp834

ASKER

Thanks, fgrushevsky.  Is there a way to do it in the code?  

The code connects to a .nsf file specified by the user (the "db" variable).  I could require that they give access to the design of the .nsf, but can't really manually go into the .nsf file myself (since it can be a different .nsf file every time someone runs it).
You could add "Call UIDoc.ExpandAllSections " before "Call uidoc.print" line, however it will expand all sections, not just this one

Avatar of amp834

ASKER

Thanks, again, fgrushevsky.  That's actually what I had tried a while ago and it didn't work, but I will try it again and see.  (I can't try it right away, I'm waiting to get a sample .nsf file that has the unexpanded sections, and should get it in a few days).  If it doesn't work, maybe you can help figure out why!
Can you find out what are the section properties for collapse/expand? the section properties will overwrite your script when it comes to printing, i.e. if section property for printing is set explicitly to "collapse when print" the section will be collapsed when you printed
Avatar of amp834

ASKER

Hmmm.  That may have been the problem before.  Is there a way to change the section properties programmatically, so I can print a specific document with everything expanded?
Well, technically you should be able to access section using NotesRichTextSection class.
It has read-write property IsExpanded that you can change. It should work in R7.
In R6 - according to Help - "For Release 6, IsExpanded is reliable only if "Don't auto expand or collapse" is set for the environment in which the code is running (Previewed, Opened for reading, Opened for editing, or Printed). This is the default setting. IsExpanded is not reliable where "Auto-expand section" or "Auto-collapse section" is set."
Avatar of amp834

ASKER

Ok, I have a sample .nsf file, and have tried the NotesRichTextSection stuff.  In the code below, I get the "Body item does not contain a section".

I have attached a screen image of what the document looks like.  The "Standard Procedures" and the "Tailored Procedures" both have a little triangle that points to right when the "section" is compressed, and points down when it is open.  In the image, I left Standard Procedures closed and made Tailored Procedures open.

Can this be something other than RTF sections?  How could I tell it to print everything? (i.e. expand everything before printing).  Maybe it's a form?  Maybe it's something other than Body?  How can I find out?
	Dim rti As NotesRichTextItem
	Set rti = doc.GetFirstItem("Body")
	Dim rtnav As NotesRichTextNavigator
	Set rtnav = rti.CreateNavigator
	If Not rtnav.FindFirstElement(RTELEM_TYPE_SECTION) Then
		Messagebox "Body item does not contain a section,",,"Error"
		Exit Sub
	End If
	Messagebox "looking at GetRichTextItem 4"
	Dim rts As NotesRichTextSection
	Do
		Set rts = rtnav.GetElement
		Messagebox "Bar color = " & _
		rts.BarColor.NotesColor & Chr(13) & _
		"Is expanded = " & rts.IsExpanded & Chr(13) & _
		"Title style font = " & rts.TitleStyle.NotesFont _
		,, rts.Title
	Loop While rtnav.FindNextElement(RTELEM_TYPE_SECTION, 1)

Open in new window

LotusNotesDoc1.jpg
The richtext item name that contains the sections might be "Body" something other than "Body". Even if it is called "body" you might have more then one item with the same name. You need to go through all items in the document to be sure - something like this...
Dim Session As New NotesSession
Dim Db As NotesDatabase
Dim Doc As NotesDocument
Dim Coll As NotesDocumentCollection
Dim rtnav As NotesRichTextNavigator
	
Set Db=Session.CurrentDatabase
	
Set Coll=DB.UnprocessedDocuments
Set Doc = Coll.GetFirstDocument
	
Forall item In doc.Items
		
                  If item.type = RICHTEXT  Then
			
			
		Set rtnav = item.CreateNavigator
		If Not rtnav.FindFirstElement(RTELEM_TYPE_SECTION) Then
			Messagebox "Body item does not contain a section,",,"Error"
			Set doc = Nothing
			Set coll = Nothing
			Set db = Nothing
			Exit Sub
		End If
		Messagebox "Section found"
		
		Dim rts As NotesRichTextSection
		count% = 0
		
		Do
			count% = count% + 1
			Set rts = rtnav.GetElement
			Messagebox "Section " & count%  _
			,, rts.Title
		Loop While rtnav.FindNextElement
		
		End If
		
End Forall

Open in new window

Avatar of amp834

ASKER

Hi again.  I put the code below (slight modification of the code you pasted), it never hits the "Section found" messagebox.

However, if i do

      Set uidoc = workspace.EditDocument(False,doc,True)      
      uidoc.ExpandAllSections
        a. at this point in the editor, all the sections are expanded
      Call uidoc.print(1,,,False)
        b.  some of the sections print expanded, some collapsed

1. For (a), why doesn't the code below do the same thing?  It does find Rich Text items, but doesn't find any sections for them.  Should I be using doc or uidoc there?

2. For (b), you mentioned the design of the form could force some sections to be collapsed.  Is there any way to programatically force it to expand while printing?  I can programatically copy the uidoc to my .ntf if necessary.

Thanks, again.

(by the way, I raised the point value of this question!)
	Dim strLog As String
	strLog=""
	Messagebox "Searching for sections"
	Forall item In doc.Items
		'strLog = strLog & item.name & ":" & item.type & " | "
		'Messagebox "Item type = " & item.type
		If item.type = RICHTEXT  Then
			strLog = strLog & item.name & ":" & item.type & " | "
			'strLog = strLog & "<-RT "
			Set rtnav = item.CreateNavigator
			If rtnav.FindFirstElement(RTELEM_TYPE_SECTION) Then
				Messagebox "Section found"
				Dim rts As NotesRichTextSection
				count% = 0
				Do
					count% = count% + 1
					Set rts = rtnav.GetElement
					Messagebox "Section " & count% ,, rts.Title
				Loop While rtnav.FindNextElement
			End If
		End If
	End Forall	
	Messagebox strLog

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Felix Grushevsky
Felix Grushevsky
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
So far I don't see how form based section can be programattically extended. Do you know how many different forms you have to open and print? If the number of forms is limeted, it would it be feasable to design the same number of forms for printing only. Than when you open original document you will copy all items into new document replacing original form with print form, print the document and discard new document
Avatar of amp834

ASKER

As far as I can tell, also, there is no way of printing from within Lotus Notes and forcing all the sections to expand, without having designer rights to the database that has the form.  And then, you would have to do it manually.

If this is your conclusion, too, maybe the next best thing is to extract all the sections into an html or rtf document and print it using another program.  Can you suggest some ways of doing this?
Avatar of amp834

ASKER

One more thought:

Copy the document into another database (for example, from the .nsf to the .ntf that has my design in it; but the original form for that is not copied), and print from there.  I don't know if the original form is referenced in the copy or not, or how the copy works.  Just an idea in case you have any insight into it.

Regards
Masoud
Masoud

One more thing to try. render original document into richtextitem then print new doc - something like below

	Dim session As New NotesSession
	Dim db As NotesDatabase
	Dim collection As NotesDocumentCollection
	Dim docA As NotesDocument
	Dim docB As NotesDocument
	Dim rtitem As NotesRichTextItem
	Dim success As Variant
	Set db = session.CurrentDatabase
	Set doc = db.GetDocumentByUNID(strArg)
	
	Set docB = New NotesDocument( db )
	Set rtitem = New NotesRichTextItem( docB, "Body" )
	docB.Form = "PrintForm"
	success = doc.RenderToRTItem( rtitem )
	
	Set uidoc = workspace.EditDocument(False,docB,True)	
	Call uidoc.print(1,,,False)

Open in new window

another suggestion as mention before would be to create your own forms for printing. when you open original document you will copy all items into new document replacing original form with print form, print the document and discard new document - see example below
	Dim Db As NotesDocument
	Dim PrintDb As NotesDocument
	Dim Doc As NotesDocument
	Dim PrintDoc As NotesDocument
	Dim Session As New NotesSession
	
	Set PrintDB = Session.CurrentDatabase
	Set Db = Session.GetDatabase("myserver","mydb",False)
	
	Set doc = db.GetDocumentByUNID(strArg)
	If (doc Is Nothing) Then
		strRet="Error: could not open specified email item"
		Exit Sub
	End If
	Set PrintDoc = PrintDb.CreateDocument
	Call doc.CopyAllItems( PrintDoc, True )
	Select Case Doc.Form 
	Case "formA" : PrintDoc.Form = "PrintFormA"
	Case "formB" : PrintDoc.Form = "PrintFormB"
	Case "formC" : PrintDoc.Form = "PrintFormC"
	Case	Else
		PrintDoc.Form = "PrintFormOther"
	End Select
	Call PrintDoc.ComputeWithForm(False,False)
	
	
	Set uidoc = workspace.EditDocument(False,PrintDoc,True)	
	Call uidoc.print(1,,,False)
	
	
	Exit Sub

Open in new window

Avatar of amp834

ASKER

I tried the "copy doc to another db" with some sample docs from various .nsf files, it doesn't work well since I need the original form, which I don't have access to.

The other thing I tried is the @Command(FileExport...) as RTF, it exports to a good printable format, except some tables it creates are too wide and get chopped off on the right.

Regardless, I don't know how to export as RTF from a LotusScript, just from the formula language.  

Is there a way to do this from LotusScript?  
Is there something I can do about the RTF file's formatting problem?
Any other ideas?

Since this is going on and on, I'm increasing the point value again!

--Masoud
Masoud

Have you tried the script were you render original document into rich text field within another document? I pasted script example on 02.27.2008 at 03:41PM EST
Avatar of amp834

ASKER

I hadn't tried it earlier (I had misread it to mean "it only copies the 'Body' of the original email", but I see it copies everything INTO the Body).  I just tried it, it is almost ok, but missing some information from the top of the original document.  And the sections are not expanded, even if I add uidoc.ExpandAllSections.

I also get "Class or type name not found: UIMEMODOCUMENT" when I run the code (I create the copy into a different db, just to be sure it's not referencing the original db!), but it runs through after I press OK.

Maybe we can render the RTF to a temporary area, and save the RTF.


the error means you have a typo somewhere in the code.

The last thing you can try is something like

Dim doc As NotesDocument
Set doc = db.GetDocumentByUNID(strArg)
Set uidoc = workspace.EditDocument(False,doc,True)
Call UIDoc.ExpandAllSections
Call UIDoc.SelectAll
Call UIDoc.Copy

This should get you current expanded document in the clipboard - from there you can either create new document with Richtextfield and paste it there, or paste it in something else (word?) and then print. It might work, but most likely it will not going to be pretty :(
 
Masoud

if have limited number of the source documents then you can design your own printing forms. You don't copy the whole source doc, you use copyallitems instead and replace original form with the form you design. I believe that would be the best way to print what you want, but it feasable only when you have limited number of source forms
Avatar of amp834

ASKER

Hi Again

Is copying the form possible even if I don't have design rights to the .nsf file that contains the user's documents?  (And for my project, I would only be able to do it in code, not manually--is there code that can create forms and copy elements from one form to another?)

The "Select all" does not select everything in the form for some reason.  If I manually use the mouse, I can select more.  (The UI's menu "Select All" does not select everything either).  So the best "to RTF" solution is the "Export", if I can find a way to export using LotusScript instead of the formula language.

For the "Class or type name not found: UIMEMODOCUMENT"  error, I am pasting my code.  I can't see an error in it, maybe you can see something.

I'm increasing the point value once more!  When it hits the limit, I may give up!  :)  Thanks for your help so far.
	' doesn't work:  the original form is not in the new database, and if the form has code, it gives errors
	' try copying the document to the another database
	Dim PrintDb As NotesDatabase
	Dim PrintDoc As NotesDocument
	'Set PrintDb = session.CurrentDatabase
	Set PrintDb = session.GetDatabase( "", "C:\MyDb.ntf" )
	Set PrintDoc = PrintDb.CreateDocument
	Call doc.CopyAllItems( PrintDoc, True )
	'PrintDoc.Form = "Memo"
'	Select Case Doc.Form 
'	Case "formA" : PrintDoc.Form = "PrintFormA"
'	Case "formB" : PrintDoc.Form = "PrintFormB"
'	Case "formC" : PrintDoc.Form = "PrintFormC"
'	Case    Else
'		PrintDoc.Form = "PrintFormOther"
'	End Select
	Call PrintDoc.ComputeWithForm(False,False)
	Set uidoc = workspace.EditDocument(True,PrintDoc,False)
	uidoc.ExpandAllSections

Open in new window

UIMEMODOCUMENT is one of the classes in the CoreEmailClasses in the script libraries in mail templates.  Looks like in your "doc" document form was stored with the document, but when you copy all items into new database , new database has no script libraries, so you get error when you open document. I did not think of that :(

Anyway, if you like to export documents into RTF using lotusscript, I suggest you use Exporter class written by Daniel Eriksson. It can be downloaded from here:

http://www.abc.se/~m9071/lss/
Avatar of amp834

ASKER

I tried Daniel's export, the .rtf file is buggy, some of the tables in the rtf are corrupt (when I open it in Word).    I was reading about the Lotus "CD" files, it may be buggy.  If there is a way to Render the entire document to rtf and get the rtf stream as text, I could save it myself.

What about exporting to HTML, is there a simple way of doing that?  Any kind of output with formatting would work too!
Avatar of amp834

ASKER

My current conclusion is:  If the form forces a section to be closed when printing, you can't change that behavior without editing the form (so you need design access to the .nsf form).  Thanks for everyone's help and suggestions.