Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print PDF files to a specific printer 2

Status
Not open for further replies.

linousa

IS-IT--Management
Mar 8, 2013
79
US
I have a local folder that gets PDF files and depending on their file names I need to have them printed to a specific printer.
Example:
c:\print\pr1.pdf -> printer_1
c:\print\pr2.pdf -> printer_2
c:\print\pr3.pdf -> printer_3

ShellExecute leaves Acrobat open after printing:
Code:
lcFile = 'c:\print\pr1.pdf'
lcPrinter =  'printer_1'
DECLARE Integer ShellExecute ;
   IN shell32.dll ;
   Integer hwndParent, ;
   String cVerb, ;
   String cFilename, ;
   String cParameters, ;
   String cDirectory, ;
   Integer nCmdShow
ShellExecute( _SCREEN.HWnd , [printto] , lcFile , ["] + lcPrinter + ["] , [] , 0 )
CLEAR DLLS [ShellExecute]

Same problem with Run command:
Code:
RUN /N C:\Program Files (x86)\Adobe\Acrobat DC\Acrobat\Acrobat.exe /t "c:\print\pr1.pdf" "printer_1"

 
I had the same problem a few years ago. I didn't find a solution at the time, and was obliged to instruct the users to close the PDF viewer manually.

That said, it might be possible to do something like this:

Code:
oWS = CREATEOBJECT("wscript.shell")
oWS.AppActivate("window")
oWS.SendKeys("% C")

Where it says "window title", insert the actual text from the title bar of your PDF viewer.

The parameter to the SendKeys method is [highlight #FCE94F][tt]% C[/tt][/highlight], which sends Alt+Space, followed by the letter C. In many applications, that character sequence will close the application. It may be different for your PDF viewer.

You would execute the above code after the PDF has been printed. You may need to introduce a delay after your ShellExecute() and before executing the above code, to allow time for the printing to complete.

The above code is off the top of my head. I haven't actually used it myself, and it might need some tweaking. But give it a try and report back.

EDIT: Another option would be to send Alt+F4 to close the viewer. In that case, it would be [tt]oWS.SendKeys("%{F4}")[/tt].
Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top