| | |
help with printing multiple lines print a txt file
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Oct 2008
Posts: 23
Reputation:
Solved Threads: 0
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
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
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.
★ 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.
•
•
Join Date: Oct 2008
Posts: 23
Reputation:
Solved Threads: 0
i am using:
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
php Syntax (Toggle Plain Text)
$file = 'receipt.txt'; $handle = printer_open('HP LaserJet 4000 Series PCL6'); printer_set_option($handle, PRINTER_SCALE, 75); printer_start_doc($handle, "My Document"); printer_start_page($handle); printer_write($handle, "$file"); printer_end_page($handle); printer_end_doc($handle); 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
Check out this and look into getting the entire file into a variable with
For this same reason I don't know how a new line command should be issued. Try the following and see what happens:
Also try:
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.
"\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");
★ "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.
★ 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.
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.
★ 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.
•
•
Join Date: Oct 2008
Posts: 23
Reputation:
Solved Threads: 0
Hi
I have tryed
This seems to print 2 seperate pages
line 1 is one page
line 2 is the other page
I have tryed
php Syntax (Toggle Plain Text)
printer_write($handle, "Line 1"); printer_write($handle, "Line 2");
line 1 is one page
line 2 is the other page
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.
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.
★ 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.
•
•
Join Date: Oct 2008
Posts: 23
Reputation:
Solved Threads: 0
Thank you very much for your help so far :o)
ok i have completed the other test too.
It looks like that the 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
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
ok i have completed the other test too.
It looks like that the
php Syntax (Toggle Plain Text)
printer_write($handle, "Text \n\rTo print");
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)
<?php $file_handle = fopen("receipt.txt", "rb"); while (!feof($file_handle) ) { $line_of_text = fgets($file_handle); $parts = explode(':', $line_of_text); print $parts[0] . $parts[1]. "<BR>"; } fclose($file_handle); ?>
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
![]() |
| Thread Tools | Search this Thread |
advanced apache api array beginner binary broken cakephp checkbox class cms code cookies cron curl database date datepart display dropdownlist dynamic echo email eregi error execution file files folder form forms function functions google head href htaccess html if...loop image include includingmysecondfileinthechain insert ip javascript job joomla jquery key library limit link login mail menu mlm multiple mysql oop password paypal pdf pdfdownload php phpvotingscript problem query radio random recursion remote screen script search server sessions smarty sms soap sorting source space sql startup stored syntax system table traffic tutorial update upload url validator variable video web xml youtube zend





