I'm developing an inventory management system for the company and the client needs the system to print the labels on a special printer for labels (Datamax I-4210) for registered products.
The system is web and is on a server at the company itself and is networked with the printer.
Yesterday I spent the whole day researching solutions but I was not successful. I actually know that it's possible to send commands to printers via socket , but it's my first experience with such functionality and I'm really pretty lost. I have no problem sending the sockets and even 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 port of the printer so I can send the sockets with the commands. At 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 obtain the data it needs to somehow send the commands. It can't be used by me since the system is in PHP and I can't get this data from the printer.
I already had to solve a scenario close to this one.
If you use Linux you can map the network printer so that it is available through cups with the lp command.
From that it is possible to call in php the command lp with a function of the type shell_exec() .
The solution I adopted when I had to solve this problem was to generate the barcode in PPLA and save it in a temporary file. Once this was done, it was enough to send the lp command to CUPS and it would turn to capturing the file and printing.
Some important considerations before adopting this solution:
- The printer must be mappable by Linux. To solve the problem, we mapped the printer through the mac-address of the computer it was connected to;
- You can send anything to print as long as you have the correct driver installed. In my case we didn't have a driver so as a palliative we mapped it with a CUPS plain text driver and started sending a PPLA file for printing.