help with printing multiple lines print a txt file

Thread Solved

Join Date: Oct 2005
Posts: 93
Reputation: humbug is an unknown quantity at this point 
Solved Threads: 13
humbug's Avatar
humbug humbug is offline Offline
Junior Poster in Training

Re: help with printing multiple lines print a txt file

 
0
  #11
Oct 30th, 2008
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:

  1. $text_to_print = file_get_contents('receipt.txt');
  2. //Use this next line only if it doesn't work without it,
  3. //ie prints "Text \n\nTo print" instead of "Text \nTo print"
  4. $text_to_print = str_replace('\n', '\r\n', $text_to_print);
  5.  
  6. //yada yada, printer stuff
  7. printer_write($handle, $text_to_print);
  8. //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:

  1. $text_to_print = '';
  2. //load mysql info into an array using:
  3. $data = mysql_fetch_array($result, MYSQL_ASSOC);
  4.  
  5. $text_to_print .= "Name: $data['name']\r\n";
  6. $text_to_print .= "Date: $data['date']\r\n";
  7. //etc.

php.net is the best place to get help on any specific function in my humble opinion.
Last edited by humbug; Oct 30th, 2008 at 11:08 pm. Reason: One letter makes all the difference
"If your not having fun, your doing something wrong." - Humbug
★ Did I help you out? Did I piss you off? Add to my reputation!
The Gabriel Method is a great book for losing weight and keeping healthy - I know Jon Gabriel Personally.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 23
Reputation: psycho007 is an unknown quantity at this point 
Solved Threads: 0
psycho007 psycho007 is offline Offline
Newbie Poster

Re: help with printing multiple lines print a txt file

 
0
  #12
Nov 2nd, 2008
hi all

having spent a large amount of time studing the ways to print using php I have finaly figured out the best solution. I have decided NOT to use the text file, but to print directly from a query to the mysql database. the function printer_draw_text is the way forward which can be used multiple times in one page.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC