escpos-php icon indicating copy to clipboard operation
escpos-php copied to clipboard

Print on server with usb thermal printer using mike42 / escpos-php in codeignter

Open muhtashim-prog opened this issue 2 years ago • 8 comments

I'm using POS and my PHP code is running on server, So I want to print my receipt with usb thermal printer using mike42 / escpos-php in codeignter. On localhost it can print perfectly but when i moved towards live server than im unable to communicate with my usb printer. Is there any way to do this @mike42

muhtashim-prog avatar Dec 22 '21 05:12 muhtashim-prog

same here

fadhlis avatar Dec 25 '21 10:12 fadhlis

Same issue

engrSakir avatar Feb 08 '22 15:02 engrSakir

Please help us if possible @mike42

engrSakir avatar Feb 08 '22 15:02 engrSakir

the problem is that you can't put files or create files on the print path from outside the network where the printer is connected, so the solution is to do a data transfer to the local server that is connected to the printer,

ybsapp avatar Feb 13 '22 02:02 ybsapp

This has been answered plenty of times before as it is not possible without workarounds. that being said, my workaround towards this is to share the printer of each client to the network, then use the Network Printer capabilities of esc-pos with the IP address as a parameter of my function which prints the receipt. It's quite hacky but it works. Note: as of the time of writing this post you can't obtain client's ip natively now on chrome browser, you must disable some flags to make it work. Cheers.

xcomsw avatar Apr 11 '22 02:04 xcomsw

@xcomsw would you document the process you did and share a link kindly?

mutiemule avatar Apr 11 '22 21:04 mutiemule

You may need to use RawPrintServer for each client PC for this to work then share each client printer to the network. I wrote a simple nodejs program that will fetch the client IP and launch RawPrintServer on startup. Once the client logged in to my PHP Program (server). The client program will send the client's IP to the server once the print event is triggered, it will be assigned to a variable and will be used on the NetworkPrintConnector(); as per usual.

Note: This is a very hacky approach and will only work on a local (network) setup. If you need to put your server online you may need to configure some sort of port forwarding or a VPN to make it work.

xcomsw avatar Apr 12 '22 00:04 xcomsw

Printing on local will work well with this package.

However, to print online, you will need to develop a desktop service which has to be installed on the local computer where you need printing to be done. This is because PHP is a server-side scripting language, so once you put this online, it won't be able to communicate to the local printer. Thus, you need a client service running on the local machine and this is where electron js and node js come into play.

I resolved this by developing an electron js service based on node-escpos package which can receive commands from the online print command and then communicate those commands to the printer through USB.

Operating System does not matter in this case, you can be hosting on Linux based server and printing on a windows server. This desktop service interfaces between the online service and the local service.

You can check out the node-escpos printer driver package for some inspiration on how to go about this.

mutiemule avatar Apr 30 '22 10:04 mutiemule