Link to home
Start Free TrialLog in
Avatar of chaintm
chaintm

asked on

Print Direct PHP <or> Other ways of printing, examples within.

My client needs to print php generated pages after an order is taken to the dot matrix printer on the network
while leaving the client default printer setting alone. So with a good amount
of research I found the following....


==================================================================
<script language='VBScript'>
Sub Print()
       OLECMDID_PRINT = 6
       OLECMDEXECOPT_DONTPROMPTUSER = 2
       OLECMDEXECOPT_PROMPTUSER = 1
       call WB.ExecWB(OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER,1)
End Sub
document.write "<object ID='WB' WIDTH=0 HEIGHT=0 CLASSID='CLSID:8856F961-340A-11D0-A96B-00C04FD705A2'></object>"
</script>
 
&&&&

<script language="javascript">
window.onload=window.print();
</script>
===================================================

bypasses printing prompt window, this works great if the default is the printer that we want to print too. however the clients computers each have their own and then the network. default to network could be great, but we don't want accidental printing on our invoices of say an email or private info due to a bad click by the user! OPS!


What I want to do is again print directly to the network printer, every client comp has the driver so if there was also maybe a way to change the default to another with a prompt? IE client doesn't pick from default printer window but I give them the option in the browser with a pop-up, I have thought about doing this with changing the default printer as well doing the following....

==============================================
<script>
function addPrinter25()
{
var x=confirm("You are about to add printer LON-691-08-P206. Would you like to make this your default printer?")
if (x==true)
{
WshNetwork = new ActiveXObject("WScript.Network");
var PrinterPath = "\\\\emalonptr00\\lon-691-08-p206";
WshNetwork.AddWindowsPrinterConnection(PrinterPath);
WshNetwork.SetDefaultPrinter(PrinterPath);
alert("Printer LON-691-08-P206 has been added successfully and set as default")
}
else
{
WshNetwork = new ActiveXObject("WScript.Network");
var PrinterPath = "\\\\emalonptr00\\lon-691-08-p206";
WshNetwork.AddWindowsPrinterConnection(PrinterPath);
alert("Printer LON-691-08-P206 has been added successfully")
}
}
</script>
============================================

I found the excample on the web, it's a good way of doing it, but having issue implmenting it. So I looked into direct printing and added the print.dll to my server and tested that with a text command. Which printed fine however doing the below to attempt to access a generated file is having a bad result. Converting to pdf is not possible btw, that is being used in other applications atm.

=============================================
///////
$filename = '"order_items_print.php?all=".$oldvalues["Order_num"]?>"';
///////
ob_start();
include $filename;
$contents = ob_get_contents();
ob_end_clean();
///////
$handle = printer_open();
printer_set_option($handle, PRINTER_MODE, "raw");
printer_write($handle,$contents, "test");
printer_close($handle);
///////
==============================================

will not work, or at least, I can't get a hold of the generated page. (error)

==================================
Error description include("order_items_print.php?all=".$oldvalues["Order_num"]?>") [function.include]: failed to open stream: No such file or directory
URL *******************/*******************/order_items_print.php?all=".$oldvalues["Order_num"]?>
Error file C:\vhosts\*******************\output\include\order_items_events.php
Error line 2153
SQL query SELECT `ItemName` FROM `items` WHERE `ItemID` = 6
==================================



which I am running around in circles, I have no problem accessing my network printer as I was able to do text testing through the php code. Just
getting a rendered page is the issue here and putting that to the network printer.

This is again an intranet application, I have full access to the apache 2.2.6 , php5, mysql , win2008 server and all clients and all code
as I am writing it myself. I am just stumped, I know I am missing something here.

Getting this done will finally finish this 3 year project in the making! So to me worth everypoint for the right answer...
I do request that if you know a soultion, please provide relative example code. IE like I posted here, I can then read it
undestand what you are talking about and go from there.

This question is defintily one needed to be answered by an expert in the field, I have been in this industry 20+ years and
sadly I can't figure this one out for the life of me ever sense the changes to IE 4 and above.

Finally I know about the activex printing out there http://www.zeepe.com/zeepeinfo/default.asp which paying a yearly fee is just not worth it to the client.  I am thinking maybe even a keylogger at this point, but rather attempt to keep it all in one application.  Another thougth I was having is capturing the URL then using a keylogger to say "ok this is the printer to goto" but no luck finding anything out there yet. I am open for discussion of course, however again if your going to realted directly to code please provide examples, it's easy to talk to the talk, but to walk it is a whole other story.

Noel B.
ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of chaintm
chaintm

ASKER

Thank you, I will look into apache once I get back to work on monday and see if this is viable.

Noel B.
Avatar of chaintm

ASKER

Follow up, Eh I couldn't wait :) So I did some searching, well now I know why people don't CGI anymore eeegads! hehe, reminds me of DOS days. Anyways, I will need to find an alternative solution to this or ask here for CGI assistance. I again am a coder for many years, so I can figure anything out given enough time, thou I need a place to start.

Setting up CGI, simple enough, getting it to access my printer and be called from a client hitting a certain invoice print page I will get lost. Being that CGI is a script language, it shouldn't be too rough, always starting out in something can be somewhat of a nightmare. Oh and yes, I know, been doing this 20+ years, How don't I know about CGI by now? Eh, lucky I guess ;P hehe..
Avatar of chaintm

ASKER

It leads off to a "possble" solution but doesn't help with someone not in the know... something like "try looking here" or a lead would have been better. Other then that, at least I have a point in a direction I can work with.
Sorry I couldn't help more but CGI is something I know about but I haven't done anything like what you asking.  Note that CGI is not limited to Perl, any language or executable can be used if you set it up for it.

In general, printing on paper from browsers is a pain.  Browsers are not formatted for paper printing which is why a lot of people turn to PDF for it.  Thanks for the points though.
I found an example that actually works on my networked LJ4 printer.  I'm not sure how to get it to work with your PHP text though.
#!/usr/bin/perl
use IO::Socket;
#!$host=shift @ARGV;
#!$port=shift @ARGV;
$host="10.202.46.31";
$port="9100";
$socket=IO::Socket::INET->new(PeerAddr=> $host, PeerPort=> $port, Proto=> 'tcp',
Type=> SOCK_STREAM) or die "Can't talk to $host at $port";

while (<>) {
print $socket $_;
}
close $socket;

Open in new window

That example works to print a file passed on the command line.  I don't know what to do to get it to accept text passed on the command line or thru 'stdin'.