Copy link to clipboard
Copied
I want to print some pdf files using a simple vbscript running on XP. I tried this and it didn't work:
Set objAcroPDF = CreateObject("AcroPDF.PDF")
objAcroPDF.LoadFile("C:\D2\Scanner\test.pdf")
objAcroPDF.PrintAll
Set objAcroPDF = Nothing
I got the script from this website.
http://www.aspfree.com/c/a/Windows-Scripting/Printing-Documents-in-WSH/4/
But anyway, it doesn't work. Maybe it used to work and adobe changed
something or I am doing something wrong.
So my question is, how do I print pdf documents from vbscript.
I have Acrobat 9 standard installed, and so will all the users of this script.
This is vbscript running on the client.
1 Correct answer
I ask google for "vbs+print+pdf". It presented 862 000 results.
Maybe now one is interested to increase this number.
Here a simple commondline solution.
set oWsh = CreateObject ("Wscript.Shell")
oWsh.run """Acrobat.exe"" /p /h" &FileName,,true
HTH, Reinhard
Copy link to clipboard
Copied
I am suprised that no one has responded. I had this question in another forum and no one responded and a guy said to try in this forum.
Is there something real hard about this, or is it something that no one ever does? It seems to me that lots of people would need to print out PDF docs from client side VBscript. Am I in the wrong forum? A guy in the acrobat scripting forum said to try here.
Copy link to clipboard
Copied
I ask google for "vbs+print+pdf". It presented 862 000 results.
Maybe now one is interested to increase this number.
Here a simple commondline solution.
set oWsh = CreateObject ("Wscript.Shell")
oWsh.run """Acrobat.exe"" /p /h" &FileName,,true
HTH, Reinhard
Copy link to clipboard
Copied
Answer # 2 works
set oWsh = CreateObject ("Wscript.Shell")
oWsh.run """Acrobat.exe"" /p /h" &FileName,,true
Answer # 3 might work in regular VB, but you can't do shell and doevents in vbscript.
Thanks Everyone
Copy link to clipboard
Copied
Is there a way to close Acrobat in vbs? When I run the script it prints the first file perfectly, but the issue is I would like it to print a whole lot of different documents. When I manually close the program the next file will print, but the goal is automate the whole process.
Copy link to clipboard
Copied
I had to kill the Adobe Reader Process between each print so the printer could reset to the next default, ie...
Sub KillAdobe()
set wmi = getobject("winmgmts:")
wmiq = "select * from Win32_Process where name='AcroRd32.exe'"
set qresult = wmi.execQuery(wmiq)
for each process in qresult
process.terminate(1)
next
Set wmi=nothing
Set wmiq=nothing
set qresult=nothing
End Sub
Then call the function, ie KillAdobe()

Copy link to clipboard
Copied
One way of doing it is to use Acrobat's command line print options.
Here is the VBScript code for the same:
<<
Sub test()
print_mypdf ("E:\test.pdf")
End Sub
Sub print_mypdf(MyFile As String)
DoEvents
Shell "C:\Program Files\Adobe\Acrobat 9.0\Acrobat\Acrobat.exe /p /h " & MyFile, vbHide
End Sub
>>
This prints PDF to the default printer. Please see if this helps.
Copy link to clipboard
Copied
My code has a "false" at the end, while yours has a "true"
set oWsh = CreateObject ("Wscript.Shell")
oWsh.run """Acrobat.exe"" /p /h" &FileName,,false
What's the difference?
tks
Copy link to clipboard
Copied
It is vital to choose that parameter right. Documentation on Wscript.Shell.run here: .Run | VBScript | SS64.com

