Solved

Batch print PDF files from VB

Posted on 2003-11-20
17
788 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
  • 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

839 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