Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Print to PDF Agent almost working

Posted on 2011-02-14
12
Medium Priority
?
3,624 Views
Last Modified: 2013-12-18
so with help from this forum I have an agent to print selected documents and any attachments to pdfs. but the agent as written prompts me to 'Save As...' - I want to give it a specific file name without it prompting me.

here is the code:


 
OPTIONS
Option Public
Uselsx "*lsxlc" 

DECLARATIONS
Const SEE_MASK_NOCLOSEPROCESS = &H40
Const SEE_MASK_FLAG_NO_UI = &H400

Private Type SHELLEXECUTEINFO
	cbSize As Long
	fMask As Long
	hwnd As Long
	lpVerb As String
	lpFile As String
	lpParameters As String
	lpDirectory As String
	nShow As Long
	hInstApp As Long
	lpIDList As Long
	lpClass As String
	hkeyClass As Long
	dwHotKey As Long
	hIcon As Long
	hProcess As Long
End Type

Declare Function ShellExecuteEx Lib "shell32.dll"_
Alias "ShellExecuteEx" (SEI As SHELLEXECUTEINFO) As Long

Declare Function TerminateProcess Lib "kernel32"_
Alias "TerminateProcess" (Byval hProcess As Long, Byval uExitCode As Long) As Long

INITIALIZE
Sub Initialize
	
	On Error Goto ErrorHandler
	
	Dim SEI As SHELLEXECUTEINFO
	
	SEI.cbSize = Len(SEI)
	SEI.fMask = SEE_MASK_NOCLOSEPROCESS Or SEE_MASK_FLAG_NO_UI
	SEI.lpVerb = "print"
	SEI.nShow = 1
	SEI.hInstApp = 0
	SEI.lpIDList = 0
	
	Dim s As New NotesSession
	Dim session As New LCSession
	Dim db As NotesDatabase
	Dim object As NotesEmbeddedObject
	Dim dc As NotesDocumentCollection
	
	Dim doc As NotesDocument
	Dim downloadfolder As String
	
	Dim extrachar As String
	Dim filecounter As Integer
	Dim filecount As Integer
	Dim filen As Variant
	Dim antalfiler As Variant
	
	Dim i As Integer, x As Integer, y As Integer
	
	Dim sFile As String
	
	Dim uidoc As NotesUIDocument
	Dim ws As New NotesUIWorkspace
	Dim success As Variant
	
' Create a folder for temporary storage of files
	downloadfolder = Environ("tmp")
	
	Set db = s.CurrentDatabase
	
	Set dc = db.UnprocessedDocuments
	
	For i = 1 To dc.Count
		Set doc = dc.GetNthDocument( i )
		
' Print document
		Set uidoc = ws.EditDocument( False , doc , True , )
		Call uidoc.Print(1)
		
' Get all attachments and print them
		filen=Evaluate("@AttachmentNames",doc)
		antalfiler=Evaluate("@Attachments", doc)
		
		Call uidoc.Close
		Delete uidoc
		
		If antalfiler(0)>0 Then
			For filecounter=0 To antalfiler(0)-1
				x=x+1
				Set Object = doc.GetAttachment( filen(filecounter) )
				If ( object.Type = EMBED_ATTACHMENT ) Then
					fileCount = fileCount + 1
					If Dir(downloadfolder+"\"+ filen(filecounter))="" Then
						extrachar=""
					Else
' Extra character in case there are attachments with the same name
						extrachar=Left(doc.universalid,4)+"___"
					End If
					Call object.ExtractFile (downloadfolder+"\"+extrachar+ filen(filecounter) )
				End If
			Next filecounter
		End If
		
		For y = 0 To filecounter-1
			sFile = downloadfolder+"\"+extrachar+ filen(y)
			SEI.lpFile = sFile
			Call ShellExecuteEx(SEI)
			Call session.Sleep(2000)
		Next
		
' Delete all files
		Call session.Sleep(5000)
		For y = 0 To filecounter-1
			sFile = downloadfolder+"\"+extrachar+ filen(y)
			Kill sFile
		Next
		
'Call TerminateProcess(SEI.hProcess, 0)
		
	Next
	
	Exit Sub
	
ErrorHandler:
	Msgbox Error$ & " on line " & Cstr(Erl) & " in " & Lsi_info(12)
	Exit Sub
End Sub

Open in new window

0
Comment
Question by:sullisnyc44
  • 7
  • 4
12 Comments
 
LVL 22

Expert Comment

by:mbonaci
ID: 34894891
I don't see where the code prompts you with anything, I presume it's PDF printer that prompts you with file name.

BTW, you don't need LSX here. You're not using it.
So delete the line
    Uselsx "*lsxlc"

and instead of line
    Dim session As New LCSession

enter this line:
    Dim session As New NotesSession
0
 

Author Comment

by:sullisnyc44
ID: 34896605
When it creates the PDF file it prompts me to save it. I'd like it to create the file silently and move on to the next one.

It's prompting me for the file name and file location.
0
 
LVL 22

Accepted Solution

by:
mbonaci earned 500 total points
ID: 34896846
Your PDF printer asks you for path and file name, see whether you can alter its settings somewhere.

You can try to print any Word document (directly, outside Notes) using that (obviously default) PDF printer and you'll see the same dialog.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 22

Expert Comment

by:mbonaci
ID: 34896885
See your code, the line 42 says:
    SEI.lpVerb = "print"

that means that you're using the Windows API code to simulate right-click on document (in Windows Explorer) and selecting Print.
0
 

Author Comment

by:sullisnyc44
ID: 34897152
How can I generate these pdfs silently then using lotusscript?
0
 
LVL 22

Expert Comment

by:mbonaci
ID: 34897839
You obviously didn't understand the word I said.
The LotusScript is not the problem.

Do you know how you create PDFs? From the code above (and your description) it seems that you print them to PDF printer.
PDF printer is printer simulation that creates PDFs, instead of sending a document to paper.

Now do this:
1. Locate any Word document in Windows explorer
2. Right click on it and select Print

What happens? Now you see what your code does?
It detaches attachments to temp folder and does exactly what you just did, and afterwards it deletes the attachments from the temp folder.

So your problem is how to configure your PDF printer to avoid prompting a user with file-save dialog.

Go to Start > Printers & Faxes
and locate your PDF printer. Which one is it (give me as much information as you can find about that printer)?
0
 
LVL 22

Expert Comment

by:mbonaci
ID: 34897985
You use Adobe PDF Distiller?

If yes, I've just located the procedure bellow here:
http://partners.adobe.com/public/developer/en/acrobat/sdk/pdf/pdf_creation_apis_and_specs/DistillerAPIReference.pdf

And here you can find example of how to alter registry using LotusScript:
http://www.experts-exchange.com/Q_24694367.html#32888690


    P r o g r a m m a t i c   Co n t r o l
Prompting can be turned off programmatically by modifying the Windows registry. This method applies to the creation of only one PDF document by a specific application for the current user. To do this, entries are added under the Windows registry key:

HKEY_CURRENT_USER\Software\Adobe\Acrobat Distiller\PrinterJobControl

This key takes as subkeys:
  (Default)
  application

The (Default) entry is reserved for possible future use and should not be used.
The application subkey is the full path of the application that is to have prompting turned off.
The value of the application subkey is a REG_SZ value that is the full path of the output file.
For example, the following registry script would turn off prompting for the next printing performed by wordpad.exe, printing to the file c:\MyPDFoutputFileName.pdf:

Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Adobe\Acrobat Distiller\PrinterJobControl]
"C:\Program Files\Windows NT\Accessories\wordpad.exe" = "c:\MyPDFoutputFileName.pdf"

    N O T E:
Though the programming language may require that your backslashes are escaped (for example, "c:\\MyPDFoutputFileName.pdf"), the value of the registry entry must end up with just a single slash as shown above. This key, once established, remains until used and is removed once the Windows API function StartDoc(HDC hdc, CONST DOCINFO* lpdi) has successfully completed. Also note that the output folder path must already exist with read and write access for the current user and the destination file must not exist.
0
 

Author Comment

by:sullisnyc44
ID: 34900965
I have adobe professional 8
0
 
LVL 31

Assisted Solution

by:qwaletee
qwaletee earned 500 total points
ID: 34902812
Distiller is a component of Adobe Pro 8, so yep, that;'s what you're using.
0
 
LVL 22

Expert Comment

by:mbonaci
ID: 34904515
Ask additional questions if you don't understand how to implement what I suggested in previous post.
0
 

Author Closing Comment

by:sullisnyc44
ID: 34916721
I thought mbonaci was rude.
0
 
LVL 22

Expert Comment

by:mbonaci
ID: 34941496
I'm sorry you feel that way, that really wasn't my intention.
Look at it this way, it seemed to me that you were sleeping, so I felt the need to snap the fingers to wake you up. Cuz', you know, it usually becomes a little annoying when you explain something to someone two times and then he, flat out, asks you the same thing the third time.

The good thing is that the problem is solved...
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article covers general Notes 8.5 troubleshooting information including recreating the Notes\Data folder.
Sometimes clients can lose connectivity with the Lotus Notes Domino Server, but there's not always an obvious answer as to why it happens.   Read this article to follow one of the first experiences I had with Lotus Notes on a client's machine, my…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses
Course of the Month11 days, 18 hours left to enroll

916 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