Page 1 of 1 1
Topic Options
#116197 - 2004-03-16 03:34 PM Printto() Problems
Allen Administrator Offline
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 Offline
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 Offline
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
#116200 - 2004-03-16 04:40 PM Re: Printto() Problems
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4567
Loc: USA
Thanks Richard...

Using a text file it works with either your UDF or Printto(), but when I change the file to a rtf or doc, it fails. Can you try that and see what results you get?


Top
#116201 - 2004-03-16 05:02 PM Re: Printto() Problems
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
If you rioght-click on the .DOC or .RTF file, can you then use the Print option in the context menu. It is well possible that there is no PrintTo registered for the extensions .DOC and .RTF.
_________________________
There are two types of vessels, submarines and targets.

Top
#116202 - 2004-03-16 05:13 PM Re: Printto() Problems
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Hmm.

The obvious difference is that the printto method for a ".DOC" extension starts WORD in DDE mode and passed the information via DDE, whereas printing a TXT file passes the file and printer parameters (to notepad) in the command line.

[EDIT]

Just tried with a RTF file, and it printed ok

[/EDIT]


Edited by Richard H. (2004-03-16 05:16 PM)

Top
#116203 - 2004-03-16 05:14 PM Re: Printto() Problems
Allen Administrator Offline
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 Offline
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
#116205 - 2004-03-16 06:30 PM Re: Printto() Problems
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4567
Loc: USA
Richard,

Still no luck. I have tested this on two different XP SP1 machines. Any chance you are running something other than XP?

Top
#116206 - 2004-03-17 10:00 AM Re: Printto() Problems
Richard H. Administrator Offline
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 Administrator Offline
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
Page 1 of 1 1


Moderator:  Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 640 anonymous users online.
Newest Members
ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder, M_Moore
17887 Registered Users

Generated in 0.064 seconds in which 0.027 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org