Solved

Printing an existing pdf file to a printer

Posted on 2007-11-29
9
3,563 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

791 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