Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Suppressing Print dialog boxes

Status
Not open for further replies.

premski

Technical User
Jul 5, 2006
3
US
I've written a script that reads a list of files from a text file and in turn, prints each file listed in the text file. This is up to 75 pdf files for one batch file.

The script hangs once in awhile on a timing issue. Since I am using the InvokeVerbEX("Print') on the folder item (the file), the print dialog box opens. I use Sendkeys to send and Enter and, then the "Save PDF File As" box opens. I use Sendkeys to send the corrected pdf filename to the dialog box. Sometimes, the timing is wrong on these two commands and the second one is sent too early (yes, I have a wait statement).

Is there a way to check for an open dialog box like you can with an application? I want to guarantee that the keystrokes are not sent until the "Save PDF File As" box is open.

Thanks for any help!
 
AppActivate might be of use.

i would have thought you would be able to accomplish your task without the need to sendkeys

+ do you ahve one of those pdf printers setup on the machine that you are tryign to print from we had one in our last place, hmm actually i am sure that did something different like you print a word doc to the pdf printer and it sends you back via email a pdf document, i thought it was as cool as ice?
+ can you try something old school with NET USE LPT1: //name of printer/print server, then use something like c:\pdffolder\pdfA.pdf > LPT1
 
I'm very new at scripting, so I don't know all the methods available to do the automation. We use Adobe Distiller and it's set as the user's default printer. It's a type of script to be run overnight.

I'll have to try the tips you suggested.

Thanks!
 
i know this wont help with the dialogue but you might want to remove the dependancy on reading hte text file to determine which pdf's to print by considering something like

Set objFolder = FSO.GetFolder("c:\pdfs")
For Each aFile In objFolder.Files
Call printPDF(aFile.Name)
Next

i appreaciate it will be more complicated than this,,,perhaps a recursive folder/file iteration, or calling a sub routine and passing the names of the folders to search for pdf's etc,,,but just a thought
 
Actually, one of your first tips make me rethink the printing aspect. If I remove the need to rename the file to be printed, then I don't have to worry about sending key strokes.

Basically the script does the following:
1. finds out the files in a specific directory
2. converts strings in those batch files for file location
3. a directory to hold the final pdfs is created (its name matches the batch file's name)
4. for each line in the batch file (really a file name), a pdf is created.

I'm going to change #4 to copy the listed file to the directory under a new name (what i want it to be) and then print the newly named file without prompting for a file name.

I just have to remember exactly what is returned in my variables now! :-D
 
one of tsuji posts,,,,might be of use

Tek-Tips Forums is Member Supported. Click Here to donate.
tsuji (TechnicalUser) Aug 23, 2004
Hello Rhinoz,

[0] For plaintext file, in vbs, you can use scripting filesystemobject to open a filehandle which is actually ltp1: say and write to it. But, it is off here.

[1] For winword, surprisingly a commandline to print a doc is not directly available. This is how you can do it behind the screen.

CODE
wordfilespec="d:\test\abc.doc" '<<<your input here

set oword=createobject("word.application")
on error resume next
with oword
.visible=false
.documents.open wordfilespec
.printout
do until .backgroundprintingstatus=0
wscript.sleep 100
loop
end with
oword.activedocument.close false
oword.quit
set oword=nothing
on error goto 0
No error handling implemented and imposed on error resume next because you need everything hidden. If error encounters, nothing happens, no signal.

[2] For pdf, the handling is even more tricky. Commandline is available so .run method can do the printing, but not entirely hidden to users even iwindowstyle is set to hidden.

CODE
pdffilespec="d:\test\abc.pdf" '<<<your input here

exepath=chr(34) & "c:\program files\adobe\acrobat 6.0\reader\acrord32.exe" & chr(34)

set wshshell=createobject("wscript.shell")
wshshell.run exepath & " /p /h " & chr(34) & pdffilespec & chr(34),0,false
set wshshell=nothing

[2a] To be truly hidden somehow, this is very tricky. You use ie to do it. I was made aware of by and learned from a somewhat cleverest script I have seen published in the ng by certain Clinton. Here is my version.

CODE
pdffilespec="d:\test\abc.pdf" '<<<your input here

set oie=createobject("internetexplorer.application")
with oie
.navigate "about:blank"
.visible=false
.document.write "<object id='PDF' name='PDF' classid='clsid:CA8A9780-280D-11CF-A24D-444553540000'>"
.refresh
while .readystate<>4
wscript.sleep 100
wend
.document.all("PDF").loadfile pdffilespec
.document.all("PDF").printall
.quit
end with
set oie=nothing
regards - tsuji

Thank tsuji
for this valuable post!


Inappropriate post?
If so, Red Flag it!


Check out the FAQ
area for this forum!



Rhinoz (IS/IT--Manageme) Oct 19, 2004
Does this work the same for sending a .prn file to the printer?

Thank Rhinoz
for this valuable post!


Inappropriate post?
If so, Red Flag it!


Check out the FAQ
area for this forum!



tsuji (TechnicalUser) Oct 20, 2004
It is this.

CODE
prnfilespec="d:\test\abc.prn" 'user's input

set wshshell=createobject("wscript.shell")
iret=wshshell.run("%comspec% /c copy /b " & chr(34) & prnfilespec & chr(34) & " prn",0,false)
set wshshell=nothing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top