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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing from a script...HELLPPPP 1

Status
Not open for further replies.

Rhinoz

IS-IT--Management
Aug 21, 2004
3
0
0
US
Hi, not a newb but this one just escapes me...

I need a script that will print a file (doc or pdf) silently, so basically the layout will look like this...

Page loaded, calls script, script prints doc but does not show up on desktop to cover original page showing.

Hope someone can help with this REALLLLLL fast.

VBScript or Javascript, either will work.

Thanks
 
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
 
Does this work the same for sending a .prn file to the printer?
 
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
- tsuji
 
Hopefully the prn is dedicated to this PC and no other process try to use it in the mean time.
 
Hello mrmovie,

Thanks for the vote (I know it's yours). I did not find the right moment to send you my well wishes and here I do. How are you doing lately? I hope all is well now for you after all the emotion? Hope to see more of your posts.

regards - tsuji
 
Thanks tsuji, its appreaciated.
the sun is shining again :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top