Configuring an XPrinter Label Printer on Linux in VMware Workstation
An example for setting up in CentOS without a graphical shell; by analogy, you can set it up on any Linux OS.
I solve a specific problem, from php I need to print labels with arbitrary text according to a template. Since the event cannot rely on a stable Internet, and most of the automation tasks overlap with the website, we decided to work with a virtual machine on VMware.
XPrinter is also suitable for marking tasks, it is much easier to install under windows. I settled on the XP-460B model with a label width of up to 108 mm.
Since I rarely set up Linux and connect devices to it, I was looking for ready-made setup manuals, I realized that the easiest way to connect a printer is through cups. I couldnβt connect the printer via USB, no manipulations on the advice in the manuals helped, I just broke the virtual machine several times.
We download the drivers from the manufacturer's website xprintertech.com, they come in one archive for Windows, Mac and Linux
Drivers are posted on the site for a series of devices, in my case 4 inch Label Printer Drivers. As it turned out, the XP-460B has already been discontinued, I figured out which series it belongs to based on breadcrumbs of a similar XP-470B model.
Install the printer in windows, enable sharing
For Linux, the archive contains 1 file 4BARCODE. This is a 2 in 1 file, a bash script with a tar archive that unpacks itself and copies the drivers into cups. In my case, bzip2 is needed for unpacking (for the 80 mm series, a different archiver is used)
yum install cups
yum install bzip2
chmod 744 ./4BARCODE
sh ./4BARCODE
service cups start
Next you need to open localhost:631 in the browser, for convenience I make the setting to open from the browser in windows. Edit /etc/cups/cupsd.conf:
We open the link in the browser by the IP of the virtual machine, in my case 192.168.1.5:631/admin
Add a printer (you need to enter root and password)
There are 2 options that I managed to configure, via the LPD protocol and via samba.
To connect via the LPD protocol, you need to enable the service in windows (Turn Windows features on or off), restart the computer.
In the cups settings, enter lpd://192.168.1.52/Xprinter_XP-460B, where 192.168.1.52 is the IP of the computer on which the printer is installed, Xprinter_XP-460B is the name of the printer in the windows sharing settings
Select driver 4BARCODE => 4B-3064TA
We do not select anything in the parameters and do not save! I tried adjusting the label size, but then the printer doesn't work for some reason. The label size can be set in the print job.
Trying to print a test page - done!
Second option. You need to install samba, start, restart cups, then a new connection point will appear in cups, in the settings enter a line like smb://user:[email protected]/Xprinter_XP-460B. Where, user is a user in windows, the user must have a password, authorization does not pass with an empty one.
When everything worked out and the printer printed a test page, jobs can be sent through the console:
In this example, the label has dimensions of 100x100 mm, 2 mm are selected experimentally. The distance between the labels is 3 mm, but if you set the height to 103 mm, the tape shifts, it is inconvenient to tear off the label. The disadvantage of the LPD protocol is that jobs are sent as to a regular printer, the ESC / P0S format is not sent for printing, the sensor does not calibrate labels.
Then you can work with the printer through php. There are libraries for working with cups, it's easier for me to send a command to the console via exec();
Since ESC/P0S doesn't work, I decided to make templates in pdf via tFPDF library