So you want to physically print the contents of receipt.txt? What method are you using to print the first line?
humbug
Junior Poster in Training
93 posts since Oct 2005
Reputation Points: 20
Solved Threads: 13
Check out this and look into getting the entire file into a variable with "\n\r" (linefeed and carriage return) separating each line of text. Alternatively write each line to the printer with it's own call of printer_write() . The latter may be easier as you usually read data from a file line by line. It may also be torture for the printer and rather slow, I don't know how printer_write() works.
For this same reason I don't know how a new line command should be issued. Try the following and see what happens: printer_write($handle, "Text \nTo print"); This is the most likely solution and sould print: Text
To print printer_write($handle, "Text \n\rTo print"); This may be needed instead to give the above result.
Also try: printer_write($handle, "Line 1");
printer_write($handle, "Line 2");
printer_write($handle, "Line 3");
printer_write($handle, "Line 4");
And see how it reacts and if it works. If your still can't get around it then tell me how each of those tests went.
humbug
Junior Poster in Training
93 posts since Oct 2005
Reputation Points: 20
Solved Threads: 13
Also check that out. Someone said that PRINTER_MODE must be set to "RAW" for printing to work... don't quite know what was meant but have a look anyway.
humbug
Junior Poster in Training
93 posts since Oct 2005
Reputation Points: 20
Solved Threads: 13
Ok, that makes sense I guess.
What about the other tests? There has to be a character that will mean "new line" and I'm guessing that if "\n" won't work then "\r\n" will.
humbug
Junior Poster in Training
93 posts since Oct 2005
Reputation Points: 20
Solved Threads: 13
I guess that because your printing a receipt and you don't need an images, TEXT would probably be the best option (If it works just as well). Faster printing would indicate it's doing less work which can't be a bad thing.
You could use the function file_get_contents($filename) to get the contents of the file as a string. Try something like the following code:
$text_to_print = file_get_contents('receipt.txt');
//Use this next line only if it doesn't work without it,
//ie prints "Text \n\nTo print" instead of "Text \nTo print"
$text_to_print = str_replace('\n', '\r\n', $text_to_print);
//yada yada, printer stuff
printer_write($handle, $text_to_print);
//yada yada, more printer stuff
That should all work I reckon, I reckon.
BTW, when do you write the contents to the file receipt.txt ? If it's earlier on in the script and you don't need to keep receipt.txt then you may as well skip that process. For example:
$text_to_print = '';
//load mysql info into an array using:
$data = mysql_fetch_array($result, MYSQL_ASSOC);
$text_to_print .= "Name: $data['name']\r\n";
$text_to_print .= "Date: $data['date']\r\n";
//etc.
php.net is the best place to get help on any specific function in my humble opinion.
humbug
Junior Poster in Training
93 posts since Oct 2005
Reputation Points: 20
Solved Threads: 13