Solved

Printing an existing pdf file to a printer

Posted on 2007-11-29
9
3,558 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
 
LVL 38

Expert Comment

by:PaulHews
ID: 20377079
You're right it doesn't.  Not easy to close it from VBScript either.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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 your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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 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…

743 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

11 Experts available now in Live!

Get 1:1 Help Now