#116197 - 2004-03-16 03:34 PM
Printto() Problems
|
Allen
KiX Supporter
   
Registered: 2003-04-19
Posts: 4567
Loc: USA
|
I've been trying to use the Printto() UDF with no success. Lonkero mentioned a while back that he was having problems as well in this post.
Here is my code: Code:
$file="%userprofile%\desktop\test.rtf" $printer="\\computername\printername"
if exist($file) printto($file,$printer) ? @error ? @serror else ? "Invalid File/Path" endif
function PrintTo($_file,$_printer) dim $,$_ $_=split($_file,"\") if ubound($_) $_file=$_[ubound($_)] endif $_[ubound($_)]="" $_=join($_) $=createobject("shell.application") $.ShellExecute($_file, $_printer, $_, "printto", 0) exit @error endfunction
When I run the script I get: Quote:
0 The operation completed successfully.
But nothing prints. I am using XP SP1 and tried both KiXtart 4.20 and 4.22.
Any ideas?
|
|
Top
|
|
|
|
#116198 - 2004-03-16 04:26 PM
Re: Printto() Problems
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Well, this simple example works for me: Code:
funPrintByExtension("foo.txt") Function funPrintByExtension($sFileName) Dim $oShell $oShell=CreateObject("Shell.Application") $oShell.ShellExecute($sFileName,"","","print",1) If @ERROR "Error in open: "+@ERROR+": "+@SERROR+@CRLF Exit @ERROR EndIf EndFunction
This prints the file "foo.txt" to my default printer via notepad.
Change the "1" at the end of the line to "0" to hide the notepad window.
|
|
Top
|
|
|
|
#116199 - 2004-03-16 04:32 PM
Re: Printto() Problems
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
And this works using "printto"... Code:
funPrintByExtension("foo.txt","\\SGBUKLHD2K001\HMIUKLHDPR201") Function funPrintByExtension($sFileName,$sPrinter) Dim $oShell $oShell=CreateObject("Shell.Application") $oShell.ShellExecute($sFileName,$sPrinter,"","printto",1) If @ERROR "Error in open: "+@ERROR+": "+@SERROR+@CRLF Exit @ERROR EndIf EndFunction
|
|
Top
|
|
|
|
#116203 - 2004-03-16 05:14 PM
Re: Printto() Problems
|
Allen
KiX Supporter
   
Registered: 2003-04-19
Posts: 4567
Loc: USA
|
If I right click on the .doc file that does not print using the UDFs, it does have "Print" as an option. Selecting this, causes Word to fire and then successfully prints.
I've also tried using pdf files as well. PDFs print fine from the subcontext menu, but do not work with the UDF.
|
|
Top
|
|
|
|
#116204 - 2004-03-16 05:23 PM
Re: Printto() Problems
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
There is a problem with that "join".
I'm pretty sure it should be: Code:
$_=join($_,"\")
|
|
Top
|
|
|
|
#116206 - 2004-03-17 10:00 AM
Re: Printto() Problems
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
No chance at all 
I'm running on XP Pro SP1.
Did you fix the join?
I've just tried again with a Word document on a remote file and it has worked fine.
If you pass invalid values for the document and printer, so you get any errors?
Does it work if you just use the "print" method rather than "printto"?
As a sanity check, here are my RTF printto parameters:
- APPLICATION = "C:\Program Files\Microsoft Office\Office10\WINWORD.EXE" /n /dde
- DDE MESSAGE = [REM _DDE_Minimize][FileOpen("%1")][FilePrintSetup "%2 on p",.DoNotSetAsSysDefault=1][FilePrint 0][DocClose 2][FilePrintSetup ""]
- APPLICATION = WinWord
- DDE APPLICATION NOT RUNNING = [FileOpen("%1")][FilePrintSetup "%2 on p",.DoNotSetAsSysDefault=1][FilePrint 0][FileExit 2]
- TOPIC = System
|
|
Top
|
|
|
|
#116207 - 2004-03-17 07:05 PM
Re: Printto() Problems
|
Allen
KiX Supporter
   
Registered: 2003-04-19
Posts: 4567
Loc: USA
|
Quote:
APPLICATION = "C:\Program Files\Microsoft Office\Office10\WINWORD.EXE" /n /dde
Richard, Thanks for sticking in there, and providing your settings, as it proved to be very beneficial. Neither RTF or DOC had the /dde on it. Adding this made it work like a charm. 
DDE is one of those windows oddities I don't think even MS can explain. 
Thanks again.
|
|
Top
|
|
|
|
Moderator: Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 640 anonymous users online.
|
|
|