Jump to content

Printing to network printer using fsockopen


chronister

Recommended Posts

Hello,

 

I have a unique challenge. I need to print to a receipt printer over port 9100. I can manage this part. Here is what I have to do this.

 

<?php
$ipAddress = "192.168.1.150";
$toPut = "I can print this no problem \r\n\r\n This line prints too!";
$f = fsockopen($ipAddress, 9100, $errno, $errstr); 
if (!$f) 
{ 
echo "Connection To Server Failed ($errstr)"; 
}
else 
{
$x = 0;
while($x < 3)
{
	if(fwrite($f, $toPut))
	{
		echo $x.'<br>';
		$x++;
	}
}
fclose($f); 
} 
?> 

 

My challenge here is formatting the text. I am attempting to figure out how to make some text bigger/smaller or print in red (it is a 2 color epson receipt IP-based printer). I have looked at the PostScript Library and it may do what I want it to do, but I am not sure how to push the raw postscript file to the printer and have it print.

 

Anyone have any experience doing this?

 

Thanks in advance

 

Nate

I'm surprised that it lets you just send it a string with it'll print for you. I recommend googling the printer and socket connections and printer headers. Most printers communicate in a similar fashion (probably postscript as you mentioned) and as a result you need to pass postscript over the socket to the printer (this will just be a massive string)...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.