Solved

Print to PDF Agent almost working

Posted on 2011-02-14
12
3,494 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
Comment Utility
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
Comment Utility
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 250 total points
Comment Utility
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
 
LVL 22

Expert Comment

by:mbonaci
Comment Utility
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
Comment Utility
How can I generate these pdfs silently then using lotusscript?
0
 
LVL 22

Expert Comment

by:mbonaci
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 22

Expert Comment

by:mbonaci
Comment Utility
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
Comment Utility
I have adobe professional 8
0
 
LVL 31

Assisted Solution

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

Expert Comment

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

Author Closing Comment

by:sullisnyc44
Comment Utility
I thought mbonaci was rude.
0
 
LVL 22

Expert Comment

by:mbonaci
Comment Utility
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

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.

Join & Write a Comment

This is an old article, please see an updated version of this article, located here: http://www.experts-exchange.com/articles/23619/Notes-8-5x-Windows-7-Notes-info-and-tips.html
For beginners of Lotus Notes user this is important to know about the types of files and their location supported by IBM Notes. Mostly users are unaware about how many file types are created and what their usages are. This Article is fully dedicated…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 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

12 Experts available now in Live!

Get 1:1 Help Now