pacchiee Posted June 23, 2009 Share Posted June 23, 2009 Hello, I am trying to print a few lines of text using my default printer through PHP as below: <?php $handle = printer_open(); printer_write($handle, "Line1: Some Text Here\nLine2: Some More Text Here\nLine3: Some Other Text Here\nLine4: Some Text Here"); printer_close($handle); ?> This prints the 4 lines, no problem at all. But, after printing 4 lines, the page scrolls to leave the remaining page empty. Instead, what I want is the printer to stop at the 4th line after printing the 4 lines. Once I refresh the page or send another print command, it should continue printing from the 5th line onwards. This I have been trying to do since almost a month ago with no success. Can you please help? Thanks in Advance. Quote Link to comment https://forums.phpfreaks.com/topic/163376-printing-from-php/ Share on other sites More sharing options...
JonnoTheDev Posted June 23, 2009 Share Posted June 23, 2009 printers dont work like that! Quote Link to comment https://forums.phpfreaks.com/topic/163376-printing-from-php/#findComment-862018 Share on other sites More sharing options...
flyhoney Posted June 23, 2009 Share Posted June 23, 2009 What you need to do is collect ALL the output BEFORE you send it to the printer. You can do this buy storing the output in $_SESSION until you have collected all of it, and then write it to the printer. Quote Link to comment https://forums.phpfreaks.com/topic/163376-printing-from-php/#findComment-862021 Share on other sites More sharing options...
pacchiee Posted June 23, 2009 Author Share Posted June 23, 2009 What you need to do is collect ALL the output BEFORE you send it to the printer. You can do this buy storing the output in $_SESSION until you have collected all of it, and then write it to the printer. This seems to be a good idea. What I feel is, keep storing the print data in $_SESSION until it can cover a page length (say for example 40 lines). Once the data to be sent to the printer has reached a maximum length (say we fix it to some 40 lines), the print_write() should be executed. Since am new to PHP, I don't really know if this works and even don't know how to pursue this if at all it is right. Please help. Quote Link to comment https://forums.phpfreaks.com/topic/163376-printing-from-php/#findComment-862035 Share on other sites More sharing options...
JonnoTheDev Posted June 23, 2009 Share Posted June 23, 2009 Correct, but refreshing the page will not achieve this. You need a proper procedure. Quote Link to comment https://forums.phpfreaks.com/topic/163376-printing-from-php/#findComment-862040 Share on other sites More sharing options...
flyhoney Posted June 23, 2009 Share Posted June 23, 2009 Correct, but refreshing the page will not achieve this. You need a proper procedure. I have no clue what that means. Since am new to PHP, I don't really know if this works and even don't know how to pursue this if at all it is right. Well now is a great time to learn. I would hit the ground running with some google queries like: "php session tutorial" or "php sessions" or "php session howto" Quote Link to comment https://forums.phpfreaks.com/topic/163376-printing-from-php/#findComment-862042 Share on other sites More sharing options...
947740 Posted June 23, 2009 Share Posted June 23, 2009 printers dont work like that! What do you mean? Quote Link to comment https://forums.phpfreaks.com/topic/163376-printing-from-php/#findComment-862044 Share on other sites More sharing options...
JonnoTheDev Posted June 23, 2009 Share Posted June 23, 2009 printers dont work like that! A printer will output the data sent to for its given paper size. i.e if you print 3 lines on an A4 printer it will spool the whole page not stop and wait for you to print again. You need a proper procedure i.e. A system flow 1. Collect data 2. Does length of data match paper size 3. No: reset to 1 4. Yes: print 5. Unset data Quote Link to comment https://forums.phpfreaks.com/topic/163376-printing-from-php/#findComment-862047 Share on other sites More sharing options...
flyhoney Posted June 23, 2009 Share Posted June 23, 2009 Fantastic neil.johnson! You see, it's not so hard to formulate replies that are actually useful. Quote Link to comment https://forums.phpfreaks.com/topic/163376-printing-from-php/#findComment-862048 Share on other sites More sharing options...
pacchiee Posted June 23, 2009 Author Share Posted June 23, 2009 Sure, I will do a bit of homework on PHP SESSION and the procedure outlined by neil and revert back with issues. Thanks neil.johnson, flyhoney, and 947740 for your help. Meanwhile, if anyone has some other way to pursue this task, please do let me know. Quote Link to comment https://forums.phpfreaks.com/topic/163376-printing-from-php/#findComment-862049 Share on other sites More sharing options...
947740 Posted June 23, 2009 Share Posted June 23, 2009 LOL. Like I helped. Quote Link to comment https://forums.phpfreaks.com/topic/163376-printing-from-php/#findComment-862056 Share on other sites More sharing options...
pacchiee Posted June 23, 2009 Author Share Posted June 23, 2009 I just was wondering, if it was possible to set the page parameters to the printer with PHP before sending the printer_write() command?? Are there any possibilities of doing it? Quote Link to comment https://forums.phpfreaks.com/topic/163376-printing-from-php/#findComment-862349 Share on other sites More sharing options...
pkedpker Posted June 23, 2009 Share Posted June 23, 2009 by the looks of the printer tree of commands it doesn't seem possible it must only be accessible on clientside you have to set it up with your computer devices etc to get the correct parameters source: Printer() Index Edit! Actually I'm mistaken check this out.. it lets you do all sorts of stuff to how it gets printed out printer-set-option() Quote Link to comment https://forums.phpfreaks.com/topic/163376-printing-from-php/#findComment-862352 Share on other sites More sharing options...
pacchiee Posted June 27, 2009 Author Share Posted June 27, 2009 I followed printer_set_option() in the below manner <?php $handle = printer_open(); printer_set_option($handle, PRINTER_SCALE, 30); printer_write($handle, "Some Text To Print\nSome More Text"); printer_close($handle); ?> It did not work. I even tried this <?php $handle = printer_open(); printer_set_option($handle, PRINTER_PAPER_FORMAT, PRINTER_FORMAT_CUSTOM); printer_set_option($handle, PRINTER_PAPER_LENGTH, 63); printer_set_option($handle, PRINTER_PAPER_WIDTH, 84); printer_write($handle, "Some Text To Print\nSome More Text"); printer_close($handle); ?> This didn't work either. I don't know if there is something wrong in the above!! Quote Link to comment https://forums.phpfreaks.com/topic/163376-printing-from-php/#findComment-864662 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.