escpos-php
escpos-php copied to clipboard
Print on server with usb thermal printer using mike42 / escpos-php in codeignter
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
same here
Same issue
Please help us if possible @mike42
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,
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 would you document the process you did and share a link kindly?
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.
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.