Solved

Print all Documents in a View to PDF

Posted on 2007-11-15
11
757 Views
Last Modified: 2013-12-18
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

0
Comment
Question by:sval1411
  • 6
  • 4
11 Comments
 
LVL 63

Expert Comment

by:SysExpert
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 !
0
 

Author Comment

by:sval1411
ID: 20298374
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.
0
 
LVL 31

Expert Comment

by:qwaletee
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.
0
 

Author Comment

by:sval1411
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.
0
 

Author Comment

by:sval1411
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.
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 31

Expert Comment

by:qwaletee
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
object.currentView.Print

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

Author Comment

by:sval1411
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
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.
0
 
LVL 31

Accepted Solution

by:
qwaletee earned 500 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.
0
 

Author Closing Comment

by:sval1411
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.
0
 

Author Comment

by:sval1411
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.
0
 
LVL 31

Expert Comment

by:qwaletee
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.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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…
I thought it will be a good idea to make a post as it will help in case someone else faces these issues. I trust this gives an idea how each entry in Notes.ini can mean a lot for the Domino Server to be functioning properly. This article discusses t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now