… or how to use the NotesUI-classes on the server.
First I would like to thank all of you out there. I have been reading this excellent forum for many years and now I like to contribute a nice trick on how to make PDF files. I have been searching for a way to use something like the PDFCreator to print out documents on the server and store them back in a document. The problem is that the ‘print’ is only avaible in the NotesUI-classes and you can’t access them from the server. But this is one way how to do it:
-
You must have one of the clients installed on the server and using an id-file with full access to your projects.
-
Download and install the PDFCreator from PDFCreator download | SourceForge.net
Install it and make it the default printer. Create a folder like ‘c:\tmpPDF’.
Open the setting for PDFCreator and turn on autosave. Choose the <REDMON_DOCNAME> for the filename and use the directory you just created. The document title will be the file name and you can control that in your form property.
- Create an empty database on the server ‘PDFCreator.nsf’. Add your user in the ACL to access designer
Create a new empty form. Name it ‘frmPDFCreator’ and save it.
Create a document using that form and save it. Yes it is an empty document!
Open the document and bring up the Properties box. In the <+> you find the identifier. Copy the whole string.
Now the magic
- In your tmpPDF folder you create a cmdPDF.BAT file. Use your identifier and make the command line like this:
explorer.exe Notes://MYSERVER/C12572AA001F3BCB/A296C48F65435737C12572AA001F3BCD/4A8AE17653B1E5D8C12572AA0020EA3D
(should be one single line)
- Create an agent called ‘startPDFCreator’ in PDFCreator.nsf.
Select ‘Agent list selection’ and target ‘none’. On the security tab set runtime security level 3.
Dim result As Integer
result = Shell("c:\tmpPDF\cmdPDF.BAT", 1)
Save it
- Open the frmPDFCreator and in the ‘Postopen’ area you write your code. Something like this:
Sub Postopen(Source As Notesuidocument)
Dim ws As New NotesUIWorkspace
Dim view As NotesView
Dim s As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim uidoc As Notesuidocument
Dim rtitem As NotesRichTextItem
Dim object As NotesEmbeddedObject
Dim objPrinter As Variant
Set objPrinter = CreateObject( "Pdfcreator.clspdfcreator")
'***************************************************************
' SETTINGS
'***************************************************************
printerpath = "c:\tmpPDF\" ' path to PDF files - end with \
timeout = 10 ' printer timeout
Fieldname = "PDF" ' Where to store the pdf-file
'************************************************************
' Set your document here
'
' bla bla bla bla
' doc = ............................
'************************************************************
startTime! = Timer()
Call ws.EditDocument(False, doc)
Set uidoc =ws.CurrentDocument
filename = uidoc.WindowTitle
Call uidoc.Print(1 )
Do While objPrinter.Cprogramisrunning = False
'wait for the PDFCreator to start
Loop
Do While objPrinter.Cprogramisrunning = True
'Wait for PDFCreator to stop
If Timer() > timeout + startTime! Then
' Error printing timeout
Print "Timeout printing to PDFCreator"
Call uidoc.Close
Call Source.Close
Exit Sub
End If
Loop
myFile = Dir ( printerpath + filename+".pdf")
If myFile <> "" Then
Print "Time to print :" + Cstr( Timer - startTime!)
If doc.HasItem(Fieldname ) Then Call doc.RemoveItem(Fieldname)
Set rtitem = New NotesRichTextItem( doc, Fieldname )
Set object = rtitem.EmbedObject ( EMBED_ATTACHMENT, "", printerpath + myFile)
Call doc.Save(True, False )
Kill printerpath + myFile
Else
' No file found - Check PDFCreator settings
Print "No PDF file found – check PDFCreator settings"
End If
Call uidoc.Close
Call Source.Close
End Sub
- Last thing to do is to call the ‘startPDFCreator’ agent in the ‘Postsave’ in the form of the document that you want to create and attach the PDF file.
Dim s As New NotesSession
Dim db As NotesDatabase
Dim agent As NotesAgent
Set db = s.Getdatabase( myserver , "PDFCreator.nsf")
Set agent = db.GetAgent("startPDFCreator")
If agent.RunOnServer = 0 Then
Print "Agent Create PDF OK"
Else
Print "Agent Create PDF did not run"
End If
Source.Close
What happens is that when you save your document it will trigger the client on the server to open an empty document and it will execute the code for your to print out you document and save it back. It works very well and is fast to. The good thing is that the client is starting by itself if not running. You have to share the windows password then so it will not stop waiting at the prompt.
In this way you may use all the NotesUI-classes and run them on the server.
See you !