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

Link to comment
Share on other sites

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)...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.