Printing in PHP

I am developing an inventory management system for enterprise and the customer needs the system to print the labels on a special label printer (Datamax I-4210) the registered products.

The system is web and is on a server in the company itself and is networked with the printer.

Yesterday I spent all day researching solutions but did not get success. In fact I know that it is possible to send commands to printers by socket , only it's my first experience with such functionality and I'm really pretty lost. I have no problem sending the sockets and until sending commands, the problem is to be able to connect the printer to send the commands.

The problem itself is to find the IP and printer port for me to send the sockets with the commands. In the company my client already uses a desktop program called BarOne and he can print the labels. Probably because it is a desktop software it manages to manipulate the printer over the network and get the data it needs to somehow send the commands. The same cannot be used by me since the system is in PHP and I cannot get this data from the printer.

Author: Maniero, 2015-02-06

1 answers

I already had to solve a scenario close to this.
If you use Linux you can map the network printer so that it is available through cups with the lp command.
From this it is possible to call in php the lp command with a function of type shell_exec().

The solution I adopted when I had to solve this problem was to generate the barcode in PPLA and save to a temporary file. Done this just send the LP command to the CUPS and it turned in capture the file and print.

Some important considerations before adopting this solution:

  1. the printer must be mappable by Linux. To fix the problem we map the printer through the mac-address of the computer on which it was connected;
  2. it is possible to send anything for printing as long as you have the correct driver installed. In my case we had no driver so as a palliative we mapped with a plain text driver of CUPS and passed to send a PPLA file for printing.
 1
Author: jlHertel, 2015-02-06 13:19:27