How to Print in Pos printer Xprinter 58 using Javascript and Php code

Leave a Comment


 


<!DOCTYPE html>

<html>

<body>

<h2>The window.print() Method</h2>

<p>Click the button to print the current page.</p>

<button onclick="window.print()">Print this page</button>

</body>

</html>



Printing receipts at xprinter 58 mm using JavaScript and PHP

Introduction

Xprinter 58 mm is a thermal receipt printer usually used in retail and restaurant businesses. This tutorial will show you how to print the receipts from the web app using JavaScript and PHP.


What will you learn

✅ How to set Xprinter 58 mm

✅ JavaScript (web print API) and receipts using PHP (Esc/POS command)

✅ Integrate with Windows/Linux/Mac System


1. Establishment of Xprinter 58 mm

Connect the printer:

Use USB, serial (com), or network (Ethernet/WiFi).

Install a printer driver:

Download the official Xprinter website or included CD.

Ensure that it is set as a default printer.

test print:

Open the notepad, type some lessons, and press Ctrl + P to test the printing.

2. JavaScript (client-side) printing

Method 1: Using Window.Print ()

From browser to basic printing:


HTML

Copy

edit

<Button onclick = "Window.print ()"> print receipt </ button>

<Div ID = "Receipt">

    <h2> Store Name </h2>

    <p> items 1: $ 5.00 </p>

    <p> items 2: $ 10.00 </p>

    <hr>

    <p> Total: $ 15.00 </p>

</ Div>

<Style>

    @Media print {

        Button {Performance: None; ,

        #Receipt {font-shape: 12px; Width: 58 mm; ,

    ,

</ty>

✅ professionals: Work on any printer

❌ Cons: No formatting control for thermal printing


Method 2: Using JavaScript and Raw Printer Command

For better control, send the raw Esc/pos command directly to the printer.

Use QZ tray (a local print server) to send commands.


Step 1: Install QZ Tray

Download Qz tray from Qz.io.

QZ start tray and allow JavaScript access.

Step 2: JavaScript code to send print command

HTML

Copy

edit

<Script src =

<Script>

    Function printreceipt () {

        Qz.websocket.connect (). Then () => {

            Qz.printe return


If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment