Solved

Printing an existing pdf file to a printer

Posted on 2007-11-29
9
3,562 Views
Last Modified: 2012-08-13
I am trying to monitor a folder and whenever a new file goes into it...in this case pdf files...I want to print them out to a list of printers.  How do I print a pdf document from vbscript.  I am using WMI to watch the folder and check for new files.  I then need code to look at the file name and then based on the name of the file will choose a list of printers and print out to them.  I haven't had any luck in finding out how to print the pdf to a printer?
0
Comment
Question by:dis1931
  • 4
  • 3
9 Comments
 
LVL 38

Expert Comment

by:PaulHews
ID: 20376627
Something like this would work:

set objShell = CreateObject("Shell.Application")
str = "C:\PDFFile.pdf"
objShell.ShellExecute str, "", "", "print", 1
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 20376649
That sends it to the default printer...

You can set a printer like so:

strPrinterPath = "\\ComputerName\Printer Name"
Set WshNetwork = CreateObject("WScript.Network")
WshNetwork.SetDefaultPrinter strPrinterPath
0
 
LVL 10

Author Comment

by:dis1931
ID: 20377015
I am assuming however that this will not close adobe reader?
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 38

Expert Comment

by:PaulHews
ID: 20377079
You're right it doesn't.  Not easy to close it from VBScript either.
0
 
LVL 10

Author Comment

by:dis1931
ID: 20379261
AcroRd32.exe has a switch /t that takes a file location, printer name, driver, and port.  I am going to call this from a vbscript.  This does close Acrobat after it prints.  It is fairly easy to close a process from vbscript via wmi.  I also like that i don't have to change the default printer as I want to print to multiple printers and don't want to keep changing it back and forth I prefer just directing it to the printer.

Everytime i see a new pdf file...based on name I will print to certain array of printers.  I will use a loop and then call acrord32.exe for each printer...and once the process ends I will call the next print.
0
 
LVL 10

Accepted Solution

by:
dis1931 earned 0 total points
ID: 20379266
In case anyone is interested the way to kill/close a process is:

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process Where Name = 'Excel.exe'")
For Each objProcess in colProcessList
      objProcess.Terminate()
Next

This will kill all Excel.exe processes on strComputer....which is a variable.  You can set the variable to a PC Name or acquire it via other means such as WMI or have a user input...etc...
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 20386668
No objections.
0
 
LVL 1

Expert Comment

by:modus_operandi
ID: 20403130
Closed, 500 points refunded.
modus_operandi
EE Moderator
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

809 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