help with printing multiple lines print a txt file

Thread Solved

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

help with printing multiple lines print a txt file

 
1
  #1
Oct 28th, 2008
Hi there, was wondering if somebody could help me.
I currently have a project to create a php/mysql system for a local pizza company, a touch screen system. Cut a long story short, I need to be able to print multiple lines from a txt file. I have got the php to output to txt file from mysqlusing variables and I can get the php script to print 1 line. As I am new I would imagine I would need some kind of loop maybe.
would be greatfull if somebody could help. (i am using a thermal receipt till printer)

for example

receipt.txt has content

receipt number: 24
time: 22:32
date: 22/09/2008

Delivery address
Name: joe blogs
house number:
street:
town/city:
Postcode:
Tel:

Order total
15" pizza £12
order total £12
Reply With Quote Quick reply to this message  
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
  #2
Oct 29th, 2008
So you want to physically print the contents of receipt.txt? What method are you using to print the first line?
"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
  #3
Oct 29th, 2008
i am using:
  1. $file = 'receipt.txt';
  2. $handle = printer_open('HP LaserJet 4000 Series PCL6');
  3. printer_set_option($handle, PRINTER_SCALE, 75);
  4. printer_start_doc($handle, "My Document");
  5. printer_start_page($handle);
  6. printer_write($handle, "$file");
  7. printer_end_page($handle);
  8. printer_end_doc($handle);
  9. printer_close($handle);

If I replace printer_write($handle, "$file"); with printer_write($handle, "TEXT TO PRINT"); this then prints the single line of text. I am not too sure how to print all the lines in the text file
Last edited by peter_budo; Oct 29th, 2008 at 6:36 pm. Reason: Keep It Organized - please use [code] tags
Reply With Quote Quick reply to this message  
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

 
1
  #4
Oct 29th, 2008
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.
"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 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
  #5
Oct 29th, 2008
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.
"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
  #6
Oct 30th, 2008
Hi
I have tryed
  1. printer_write($handle, "Line 1");
  2. printer_write($handle, "Line 2");
This seems to print 2 seperate pages
line 1 is one page
line 2 is the other page
Reply With Quote Quick reply to this message  
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
  #7
Oct 30th, 2008
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.
"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
  #8
Oct 30th, 2008
Thank you very much for your help so far :o)

ok i have completed the other test too.

It looks like that the
  1. printer_write($handle, "Text \n\rTo print");
did write 2 seporate lines. without using the \r switch the output was:

Text

To print

if i included the \r the output was:
Text
To Print

My next step would have the php code to send the text file to an array splitting the text file for each line and sending it to a loop to print to the printer. which im not really sure how to do?

Having studyed lots of code I have found the following code will output text file to an array

  1. <?php
  2. $file_handle = fopen("receipt.txt", "rb");
  3.  
  4. while (!feof($file_handle) ) {
  5.  
  6. $line_of_text = fgets($file_handle);
  7. $parts = explode(':', $line_of_text);
  8.  
  9. print $parts[0] . $parts[1]. "<BR>";
  10. }
  11.  
  12. fclose($file_handle);
  13.  
  14. ?>
Which outputs sucessfully to the screen. But it looks like that when it gets to the end of the file having no more text to print it displays the following errors

PHP Notice: Undefined offset: 1 in C:\Inetpub\wwwroot\takeaway\receipt.php on line 25 PHP Notice: Undefined offset: 1 in C:\Inetpub\wwwroot\takeaway\receipt.php on line 25 PHP Notice: Undefined offset: 1 in C:\Inetpub\wwwroot\takeaway\receipt.php on line 25 PHP Notice: Undefined offset: 1 in C:\Inetpub\wwwroot\takeaway\receipt.php on line 25 PHP Notice: Undefined offset: 1 in C:\Inetpub\wwwroot\takeaway\receipt.php on line 25 PHP Notice: Undefined offset: 1 in C:\Inetpub\wwwroot\takeaway\receipt.php on line 25
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
  #9
Oct 30th, 2008
sorry i forgot to mension that in my last comment any lines displaying : are not shown in the output to screen
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
  #10
Oct 30th, 2008
changing the print function to RAW data seems to slow the printing speed
setting the printer function to TEXT seems to increase the speed
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