Solved

Batch print PDF files from VB

Posted on 2003-11-20
17
794 Views
Last Modified: 2008-01-16
Hi,
I want to be able to silently print batch pdf files from VB using user's default printer.
Using shell "AcroRd32 -p " command opens up print dialog that I don't need, and it can print only one pdf.


Thanks
0
Comment
Question by:bagirex
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 4
17 Comments
 
LVL 28

Accepted Solution

by:
vinnyd79 earned 250 total points
ID: 9789750
Have you using ShellExecute API to print? If you add a FilelistBox you can loop through it printing each document:

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Private Sub Form_Load()
File1.Pattern = "*.pdf"
File1.Path = "C:\Somefolder"
End Sub

Private Sub Command1_Click()
Dim i As Integer
For i = 0 To File1.ListCount - 1
    Call ShellExecute(hwnd, "Print", (File1.Path & "\" & File1.List(i)), "", "", 0)
Next i
End Sub
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9789837
I did a little example here:
http://www.angelfire.com/realm/vb-shared/pdf_print.xls
What you need to avoid dialog box is using /T modifier instead of p.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9797282
hi, any progress on this? some feedback would be nice.
Cheers
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

Author Comment

by:bagirex
ID: 9801542
I am using WIN2K, Vb6, Acrobat 6.0
Sorry about being late on this.

vinnyd79,
Thanks, it is working except Acrobat window is left open.
How to close it?
Will it work on other that WIN platforms?

Richie_Simonetti,

in modmain
Do
    ' Please check that caption of acrobat is correct,
    ' otherwise this loop will never ends.
    l = FindWindow(vbNullString, "Acrobat Reader - [" & filename & "]")
Loop While l = 0

When I've commented out all but
ShellExecute 0, "print", "C:\Program Files\Adobe\Acrobat 6.0\Reader\Acrord32.exe /t " & filename, vbNullString, vbNullString, vbHide
it didn't work either.

It kept looping.
0
 

Author Comment

by:bagirex
ID: 9801642
Richie_Simonetti,

Just read
    ' Please check that caption of acrobat is correct,
comment more carefully. Is it good idea to find acrobat instance by it's window title?
Might be differet with different versions.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9809955
Of course, you could do that way:
classname for acrobat is (at least 5.0) is:
Afx:400000:8: 10011:0:a510219
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9809963
by the way, i misread your comment, it IS searching by its window title.
0
 

Author Comment

by:bagirex
ID: 9811370
At least the good news is Acrobat Reader allows only one running instance.
Afx:400000:8: 10011:0:a510219 for classname didn't work. Mine is Adobe 6.0
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9811743
Well, if classname doesn't works, we have to moveback to findwindow api.
Please, check how acrobat show its caption with version 6.0
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9813335
Classname for version 6.0.0 in "AdobeAcrobat"
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9813478
Well, since only one instance is allowed, use code from vinnyd, just replace p modifier with t modifier.
Maybe you could call shellexecute with full path to acrobat exe only the first time and others calls to print other docs should use " /t " & filename as lpFile parameter (just a guess)
0
 

Author Comment

by:bagirex
ID: 9818260
Richie,

1.  How do you find out classname for Adobe versions? I checked my registry and couldn't find it
2. Vinnyd doesn't use any modifier. It uses only 'print' , which doesn't have modifiers!?

thanks
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9818497
1) there is a tool that comes with Visual studio called Spy, you could use it to know the class name from every window. Just moving the cursor over it.
2) Modifiers were hard to find for me but, as long as i know, using T as modifier, it doesn't shows you dialog box.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9874324
Hi, any progress on this?
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

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.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

736 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