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

x
?
Solved

Printing an existing pdf file to a printer

Posted on 2007-11-29
9
Medium Priority
?
3,574 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
8 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
Independent Software Vendors: 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 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

876 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