Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Print all Documents in a View to PDF

Posted on 2007-11-15
Medium Priority
Last Modified: 2013-12-18

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()
'Get the database Directory
notesDBDir = notesSession.GetDbDirectory("")
'Get the Database
notesDatabase = notesDBDir.OpenDatabase("test.nsf")
If Not (notesDatabase.IsOpen) Then
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

Question by:sval1411
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
LVL 63

Expert Comment

ID: 20296100
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 !

Author Comment

ID: 20298374
Thank you very much for the prompt response.

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


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.
LVL 31

Expert Comment

ID: 20301639
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.

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.


Author Comment

ID: 20303306
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.

Author Comment

ID: 20305719
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.
LVL 31

Expert Comment

ID: 20314896
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

You can also use the legacy DDE interface to do a [SelectAll] operations, or use SendKeys

Author Comment

ID: 20316048
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

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.
LVL 31

Accepted Solution

qwaletee earned 2000 total points
ID: 20323509
There is no way to trap those security messages from Notes.  What you shoudl do is find out all the certificates in use, and permanently change your ECL to allow that root certifier access to all necessary functions and/or add a permanent cross certificate to the root certificate.

Author Closing Comment

ID: 31409475
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.

Author Comment

ID: 20329885
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.
LVL 31

Expert Comment

ID: 20379622
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.

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For users on the Lotus Notes 8 Standard client, this article provides information on checking the Java Heap size and adjusting it to half of your system RAM in attempt to get the Lotus Notes 8.x Standard client to run faster.  I've had to exercise t…
  In today’s Arena we can’t imagine our lives without Internet as we are highly used to of it. If we consider our life style just for only 2 min we found that face to face communication is swapped by e-communication.  Every Where from Works place to…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : All lightning effects with instructions : http://www.mediaf…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question