Configuring an XPrinter Label Printer on Linux in VMware Workstation

An example to configure on CentOS without a graphical shell; by analogy, you can configure it on any Linux OS.

I solve a specific problem, from php you need to print labels with arbitrary text according to the template. Since it is impossible to count on a stable Internet at the event, and most of the automation tasks intersect with the website, we decided to work with the virtual machine on VMware.

XPrinter is also suitable for marking tasks; installing under windows is much easier. He stopped on the XP-460B model with a label width of up to 108 mm.



Since I rarely configure Linux and connect devices to it, I looked for ready-made configuration manuals, I realized that the easiest way to connect the printer through cups. I could not connect the printer via USB, no manipulations on the tips in the manuals helped, I just broke the virtual machine several times.

  • Download drivers from the manufacturer's website xprintertech.com, they come in one archive for Windows, Mac and Linux. The

    drivers are located 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 realized which series it belongs to in the bread crumbs of the similar XP-470B model.
  • Install the printer in windows, enable sharing

  • Linux 1 4BARCODE. ยซ2 1ยป , bash tar , cups. bzip2 ( 80 )

    yum install cups
    yum install bzip2
    chmod 744 ./4BARCODE
    sh ./4BARCODE
    service cups start
    
  • localhost:631 , , windows. /etc/cups/cupsd.conf:

    Listen localhost:631   Listen *:631
    <Location />
      Order allow,deny
      Allow localhost
      Allow 192.168.1.*  
    </Location>
    <Location /admin>
      Order allow,deny
      Allow localhost
      Allow 192.168.1.*
    </Location>
    

    631 firewall ( iptables):

    firewall-cmd --zone=public --add-port=631/tcp --permanent
    firewall-cmd --reload
    
  • IP , 192.168.1.5:631/admin

    ( root )

  • 2 , , LPD samba.

    1. LPD, windows ( Windows), .


      cups lpd://192.168.1.52/Xprinter_XP-460B, 192.168.1.52 โ€” IP , , Xprinter_XP-460B โ€” windows


      4BARCODE => 4B-3064TA


      ! , - . .


      โ€” !
    2. . samba, , cups, cups, smb://user:password@192.168.1.52/Xprinter_XP-460B. , user โ€” windows, , .

When everything turned out and the printer printed a test page, the tasks can be sent via the console:

lpr -P Xprinter_XP-460B -o media=Custom.100x102mm test.txt

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 is shifted, 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 to the printer, the sensor does not calibrate the labels.

Then you can work with the printer through php. There are libraries for working with cups, it is easier for me to send a command to the console via exec ();

Since ESC / P0S does not work, I decided to make templates in pdf via tFPDF library

require_once($_SERVER["DOCUMENT_ROOT"] . "/tfpdf/tfpdf.php");
$w = 100;
$h = 100;
$number = 59;
$pdf = new tFPDF('P', 'mm', [$w, $h]);
$pdf->SetTitle('Information');
$pdf->AddFont('Font', 'B', $_SERVER["DOCUMENT_ROOT"] . '/fonts/opensans-bold.ttf', true);
$pdf->SetTextColor(0,0,0);
$pdf->SetDrawColor(0,0,0);

$pdf->AddPage('P');
$pdf->SetDisplayMode('real','default');
$pdf->Image($_SERVER["DOCUMENT_ROOT"]. '/images/logo_site.png',$w - 4 - 28,$h - 13,28.1,9.6,'');

$pdf->SetFontSize(140);
$pdf->SetXY(0,24);
$pdf->Cell($w,$h - 45, $number,0,0,'C',0);

$pdf->SetFontSize(1);
$pdf->SetTextColor(255,255,255);
$pdf->Write(0, $number);

$pdf->Output('example.pdf','I');

exec('php label.php | lpr -P Xprinter_XP-460B -o media=Custom.100x102mm');


Done. I killed 2 days off to set up, I hope it will be useful to someone.

All Articles