Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/163376-printing-from-php/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/163376-printing-from-php/#findComment-862035
Share on other sites

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"

 

Link to comment
https://forums.phpfreaks.com/topic/163376-printing-from-php/#findComment-862042
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/163376-printing-from-php/#findComment-862047
Share on other sites

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()

Link to comment
https://forums.phpfreaks.com/topic/163376-printing-from-php/#findComment-862352
Share on other sites

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!!

Link to comment
https://forums.phpfreaks.com/topic/163376-printing-from-php/#findComment-864662
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.