Link to home
Start Free TrialLog in
Avatar of sval1411
sval1411

asked on

Print all Documents in a View to PDF

Greetings,

I am trying to print all the documents in a particular View in a given NSF. I am doing this in VB.Net by using late binding calls. Attached please find the code.

This code works fine for small NSF files, but if the NSF file contains more than 500 documents, the program crashes. I am not sure if this is a late binding issue with .Net or if its something in my code.

Please do advice if there is a better way to print the docs to pdf or the code above can be tweaked.

Any help will be greatly appreciated.

Thanks in advance.
'variable declarations
 
Dim notesSession As Domino.NotesSession
Dim notesDBDir As Domino.NotesDbDirectory
Dim notesDatabase As Domino.NotesDatabase
Dim notesView As Domino.NotesView
Dim notesDoc As Domino.NotesDocument
 
 
Dim ws As Object
Dim WSObj As Object
Dim UIDBObj As Object
Dim DBObj As Object
Dim DocObj As Object
Dim notesUIWorkspaceType As Type
 
Dim args1(0) As Object
Dim args2(5) As Object
Dim args3(0) As Object
Dim args4(0) As Object
Dim nc As Int16
Dim resObj As Object
 
 
 
public subPrintAllDocs_Inbox()
 
'Front End Classes
 
ws = CreateObject("Notes.NotesUIWorkspace")
Call ws.OpenDatabase("", "test.nsf")
 
notesUIWorkspaceType = Type.GetTypeFromProgID("Notes.NotesUIWorkspace")
 
WSObj = Activator.CreateInstance(notesUIWorkspaceType)
UIDBObj = notesUIWorkspaceType.InvokeMember("CurrentDatabase", Reflection.BindingFlags.GetProperty, Nothing, WSObj, Nothing)
 
DBObj = notesUIWorkspaceType.InvokeMember("Database", Reflection.BindingFlags.GetProperty, Nothing, UIDBObj, Nothing)
 
 
'Back End Classes
 
'Open a Session and initialize it
notesSession = New Domino.NotesSession()
notesSession.Initialize()
 
'Get the database Directory
notesDBDir = notesSession.GetDbDirectory("")
 
'Get the Database
notesDatabase = notesDBDir.OpenDatabase("test.nsf")
If Not (notesDatabase.IsOpen) Then
    notesDatabase.Open()
End If
 
'Get the ($Inbox) View
notesView = notesDatabase.GetView("($Inbox)")
 
'Start Printing Documents
notesDoc = notesView.GetFirstDocument()
 
While Not (notesDoc Is Nothing)
 
   args1(0) = CType(notesDoc.UniversalID, System.Object)
   DocObj = notesUIWorkspaceType.InvokeMember("GetDocumentByUNID", Reflection.BindingFlags.InvokeMethod, Nothing, DBObj, args1)
 
   args2(0) = CType(False, System.Object)
   args2(1) = CType(DocObj, System.Object)
   args2(2) = CType(True, System.Object)
   args2(3) = CType("", System.Object)
   args2(4) = CType(True, System.Object)
   args2(5) = CType(False, System.Object)
   resObj = notesUIWorkspaceType.InvokeMember("EditDocument", Reflection.BindingFlags.InvokeMethod, Nothing, WSObj, args2)
 
   nc = 1
   args3(0) = CType(nc, System.Object)
   notesUIWorkspaceType.InvokeMember("PRINT", Reflection.BindingFlags.InvokeMethod, Nothing, resObj, args3)
 
 
   args4(0) = CType(False, System.Object)
   notesUIWorkspaceType.InvokeMember("CLOSE", Reflection.BindingFlags.InvokeMethod, Nothing, resObj, args4)
 
   notesDoc = notesView.GetNextDocument(notesDoc)
 
End While
 
End Sub

Open in new window

Avatar of SysExpert
SysExpert
Flag of Israel image

I do not see anythng obvious that could cause this.
I would try using the latest version of  a Note client ( R 7.03 or R8 ) nad see if it still happens.

You may need to use some debugging methods that include methods of detecting memory leaks.


I hope this helps !
Avatar of sval1411
sval1411

ASKER

Thank you very much for the prompt response.

I did use some debugging and I an exception in the following method

System.RuntimeType.InvokeDispMethod

This I believe is the dispatcher for late binding calls. I see the problem is that the print is slower than document close. As in, the document has been sent to the spooler (Adobe Acrobat) and it still is being printed, while the execution of the code has moved on to the next line viz. the "Close" statement.

I am using Adobe Distiller to print. Adobe has been set as my default printer. Is ther some way I can get the status of the print (progamatically).
I wasn't able to find any APIs / Objects that Adobe provides to check the status of the print job.

Any suggestions would be greatly appreciated.


Thank you very much.
Don't open the document to print. You want to print form the view.

Call notesUIView.Print( numCopies% [, fromPage% ] [, toPage% ] [, draft ] [, pageSeparator% ] [, formOverride$ ] [, printview ] [, dateRangeBegin ] [, dateRangeEnd ] )

You'll also need to Select All first.
Thanks for the prompt reply.

I was going to explore that avenue, but I am only able to print the first document (which is the selected by default).

Any suggestions / code on Select All will the much appreciated.

Thanks again.
I changed my Lotus Notes Client, to ver 7.0.2 and I still running into the same issue.

Please do inform if there is another (stable) way to print notes documents to pdf.

Thank you very much for your assistance.
For select all, you could instantiate a Lotus.NotesSession, and use the following sequqnce for each document:

object.currentView.SelectDocument( object_that_represents_document )

When all documents have been selected, then use
object.currentView.Print

You can also use the legacy DDE interface to do a [SelectAll] operations, or use SendKeys
Thank you very much for your response.

I found another interesting thing that kinda helped my app.

I had a few nsf files that I was used for testing my app. Some nsfs had thier ODS (On Disk Structure) version as 41 and some had 43.
41 is the ODS for nsfs buit in Notes 5x and 43 is the ODS version for nsfs buit in 6x.
The Notes Client that I was installed on my system was 6.5.3. I then installed 5.3 to print the nsfs whose ODS version was 41 and it worked fine. Also I added the following garbage collection code after the "Close" statement

resObj = Nothing
GC.Collect()

resObj is the object that is returned when "EditDocument" is called (please refer to the code I had pasted in my first post)

Also when I wanted to print nsfs whose ODS version is 43, I had to uninstall and reinstall Notes 6x.

Another issue that I am facing now is, some documents when opened in Notes show a pop-up message. The pop-up generally states that a "cross-certificate" needs to be created or "Trust User" to perform this action.

Is there some way in VB.Net to know that a pop-up has appeared in Lotus Notes and how can that be handled.

Any suggestions on this will be much appreciated.

Thanks in advance.
ASKER CERTIFIED SOLUTION
Avatar of qwaletee
qwaletee

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
Thanks a lot for all the help. Totally appreciate it!!

One quick question, can you please tell me what version of Interop.Domino and Interop.Lotus come with Lotus Notes 6.5.3.

The reason I ask is, when I installed Lotus Notes 6.5.2, the Interop dlls were version 6.5 and 6.0, but when I installed Lotus Notes 6.5.3, the Interop dlls were version 1.1 and 6.0 respectively.
Can you please inform what are the versions of Interop.Domino and Interop.Louts DLLs that come with Lotus Notes 6.5.3?

Thank you.
I don't know, I would have to find a user who happens to ohave that version installed.  I probably don't have any -- those are old versions.