944,008 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 4364
  • PHP RSS
You are currently viewing page 1 of this multi-page discussion thread
Oct 28th, 2008
1

help with printing multiple lines print a txt file

Expand Post »
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
Similar Threads
Reputation Points: 14
Solved Threads: 0
Newbie Poster
psycho007 is offline Offline
23 posts
since Oct 2008
Oct 29th, 2008
0

Re: help with printing multiple lines print a txt file

So you want to physically print the contents of receipt.txt? What method are you using to print the first line?
Reputation Points: 20
Solved Threads: 13
Junior Poster in Training
humbug is offline Offline
93 posts
since Oct 2005
Oct 29th, 2008
0

Re: help with printing multiple lines print a txt file

i am using:
php Syntax (Toggle Plain Text)
  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
Reputation Points: 14
Solved Threads: 0
Newbie Poster
psycho007 is offline Offline
23 posts
since Oct 2008
Oct 29th, 2008
1

Re: help with printing multiple lines print a txt file

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.
Reputation Points: 20
Solved Threads: 13
Junior Poster in Training
humbug is offline Offline
93 posts
since Oct 2005
Oct 29th, 2008
0

Re: help with printing multiple lines print a txt file

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.
Reputation Points: 20
Solved Threads: 13
Junior Poster in Training
humbug is offline Offline
93 posts
since Oct 2005
Oct 30th, 2008
0

Re: help with printing multiple lines print a txt file

Hi
I have tryed
php Syntax (Toggle Plain Text)
  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
Reputation Points: 14
Solved Threads: 0
Newbie Poster
psycho007 is offline Offline
23 posts
since Oct 2008
Oct 30th, 2008
0

Re: help with printing multiple lines print a txt file

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.
Reputation Points: 20
Solved Threads: 13
Junior Poster in Training
humbug is offline Offline
93 posts
since Oct 2005
Oct 30th, 2008
0

Re: help with printing multiple lines print a txt file

Thank you very much for your help so far :o)

ok i have completed the other test too.

It looks like that the
php Syntax (Toggle Plain Text)
  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

php Syntax (Toggle Plain Text)
  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
Reputation Points: 14
Solved Threads: 0
Newbie Poster
psycho007 is offline Offline
23 posts
since Oct 2008
Oct 30th, 2008
0

Re: help with printing multiple lines print a txt file

sorry i forgot to mension that in my last comment any lines displaying : are not shown in the output to screen
Reputation Points: 14
Solved Threads: 0
Newbie Poster
psycho007 is offline Offline
23 posts
since Oct 2008
Oct 30th, 2008
0

Re: help with printing multiple lines print a txt file

changing the print function to RAW data seems to slow the printing speed
setting the printer function to TEXT seems to increase the speed
Reputation Points: 14
Solved Threads: 0
Newbie Poster
psycho007 is offline Offline
23 posts
since Oct 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC