Printing 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. Following is my code.

'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

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.

Subject: Printing all documents in a View to PDF

Subject: Printing all documents in a View to PDF

My usual disclaimer: I’m not an expert on this, but …

… still can’t keep my mouth shut. First off, I’m sure there is a reason you have to do this programmatically through VB instead of using the Notes clients print view functionality, so I won’t comment on it. I don’t see any code to set the active printer driver, so I assume this is always set to some PDF generator.

I can only guess, that the problem stems from opening all documents in the UI, printing it and then closing it again. I could thing about run-time problems here, like print being to slow for close.

If this should turn out to be true, you might have more luck using the Print method of the NotesUIView object.

Subject: RE: Printing all documents in a View to PDF

Thank you very much for the responses.

The issues I am running into are the ones mentioned viz., system not being well behaved and the print being too slow for document close.

Yes, I am using a print driver - PDF Distiller and its set as the default printer. I am not able to find any api / objects that Adobe provides for me to check the status of the “Print”.

I am looking into the printing via the NotesUIView Object, but I am having some difficulty figuring out the code for that. I am only able to print the first document with NotesUIView.Print and I still havent figured out how to use the “SelectDocument()” method by making a late / early binding call.

Can you please give me some sample code?

Thanks again for all the help.

Subject: RE: Printing all documents in a View to PDF

“I am only able to print the first document with NotesUIView.Print and I still havent figured out how to use the “SelectDocument()” method by making a late / early binding call.”

The document on focus is always considered “selected”, unless you explicitly select (set the checkmark in UI) one or more other documents. Unfortunately, I don’t have any sample code at hand and you will probably be faster figuring this out than me.

Subject: RE: Printing all documents in a View to PDF

Thanks for the response.

I shall poke around and try to find something. If not I shall try and use Lotus script as my last resort to print.

Thank you.

Subject: RE: Printing all documents in a View to PDF

I found some code that will let me check the status of the printer. So I close the doc only after the print is complete.

Now, after doing that by program crashes at the document close statement.

Any ideas as to why this is happening will be great.

Thank you very much.

Subject: RE: Printing all documents in a View to PDF

Greetings,

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 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 built in Notes 5x and 43 is the ODS version for nsfs built 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.