Solved

Printing an existing pdf file to a printer

Posted on 2007-11-29
9
3,559 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

932 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

10 Experts available now in Live!

Get 1:1 Help Now