Jump to content

Print image to receipt printer from PHP on Windows


Recommended Posts

I am trying to print an image to a thermal POS printer from a PHP script. I have managed to get a text file to print by saving it to a file and copying to the USB port and that works fine.

Am running PHP on Windows.

Would appreciate any assistance.

Thanks Steve

38 minutes ago, siric said:

I have managed to get a text file to print by saving it to a file and copying to the USB port and that works fine.

How does that work, exactly? Does the USB show up as a file device you can just copy files to? What does that process require you to do?

You create a port in Windows which is mapped to the USB port - in my case named Terow.  You then create your text file and copy it to the port.

 

$file =  "print.txt";

$handle = fopen($file, 'w');
$linefeed = chr(10);
$Data = "This is a test\n";
$Data .= "\n";
$Data .= "Line 1";
$Data .= "\n";
$Data .= "Line 2";
$Data .= $linefeed;
$Data .= $linefeed;

fwrite($handle, $Data);
fclose($handle);
copy($file, "//localhost/terow"); 

If I do the same with an image, as expected it prints junk.  Can't find information on how to convert the image file to data that will be accepted by the printer.

 

4 hours ago, siric said:

Can't find information on how to convert the image file to data that will be accepted by the printer.

You'll have to do that. Educated guess says the image has to be a monochrome (B&W) bitmap.

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.