PHP Thermal Printing Client-Side - php

I've got a Epson Thermal printer, model TM-T20 which I'm setting up for clients.
Our webserver is a linux server, and the client machines will be Windows machines.
Is it possible with php, to directly control the thermal printer attached to the clients computer?
I have looked at javascripts window.print(), but that is not what I want, if possible I want to bypass the print dialog.
Thanks,
Tony

No. PHP has absolutely nothing to do at all with the client's printer. If the printer was attached to the machine the PHP script is running on (i.e. the server), there may be something you could do. As it is, PHP only sends text to the client. From there, the client's browser and printer software has to handle it.
Alternatively, if the Windows box ran a print server exposing the printer that PHP could talk to over the network, you could talk to the printer directly. But that wouldn't be a normal PHP server/client relationship anymore.

printing from php isn't that easy, most web apps i have seen generate a pdf and and the clients print that.
have a look at http://www.vendhq.com/ they do a point of sale app for shops, and have something you need to download and install to print till dockets via a receipt printer. it might give you some inspiration

I have done exactly this before. It was quite tricky, using a ubuntu server on the workplace's LAN and a thermal printer on another ubuntu computer in the shipping area. That computer was running a php service listening to a port and was headless, hiding inside the cabinetry.
The business's internal web php "application" on the LAN server would coordinate with their e-commerce and UPS.com to print a shipping label. I forgot how UPS sent it but we used imagemagik to tweak the final image to the perfect pixel width. Then the LAN server would connect to the target's php socket server and it would send the proper commands to the serial port that the printer was connected to, along with the image data.
To call that solution madhatterey is an understatement... but was quite amazing to have labels appear magically upon "shipping" an order. No print dialog or anything. Cheapest solution is get an Atom box that can run Ubuntu and get a printer with a ppd file that works. Then just queue it up properly. Same concept as remote printing in linux.
You could possibly do the print request from a webpage's AJAX request and not need the extra infrastructure (or target computer's php socket server).

Related

Print from python/PHP

So, long story short, I have a site running in my home off a Raspberry Pi (Raspbian) (secured and not shared with anyone other than me, local within the network) running a down-and-dirty file upload system. I want to configure the server to automatically send any file I send to it to the printer, and print out automatically. I have CUPS installed on the pi, but I have no idea what else to do.
the printer is a wifi printer (Xerox colorcube) if that matters
I was thinking possibly a python script?
Ok so I completed the task, and I am sharing this so any voyagers who stumble across this page don't find it unanswered.
Get the solution at the github repo

make keyboard accessible for client of remote server (Raspberry pi, php)

So here is what I wanted to do. I have an Apache2 server up and running on my raspberry pi 3, which is currently serving as a webradio using php commands and mpd/mpc. The raspberry is also connected via HDMI to a display.
I now like to have another page on the webserver which let's me start different roms in an emulator and display the output signal on the display connected to the remote server and and also lets me use a controller connected also to the remote server.
This is what I have done so far.
I have successfully installed Retroarch which is up and running.
I used exec("export DISPLAY=:0.0; retroarch -c /home/pi/path/to/config -L /home/pi/path/to/libretro/core /home/pi/path/to/rom") to start the emulator on the remote sever.
The problem is as follows. Even though I started the emulation successfully on the screen I cannot use the input devices connected to the remote server. How can I make the input devices of the server accessible with a php-command or something else? Can somebody point me to a solution to achieve this? Also the exec-command does not seem to accept my arguments besides the config file argument. I guess it has to do with user rights. But I am really stuck at this point.
Thanks for any replies.
Disclaimer: This is my first post. So I am sorry for bad terminology.

Web-based printing to a remote local thermal receipt printer

I have a web-based point of sale application on PHP apache. User access the POS from another computer (within the network) to perform the transaction, then print on their local machine. Currently the print format is in html, displayed and printed on the user machine.
I am planning to add support for receipt printer like epson thermal or dot matrix, star. I have searched code escpos php code that might be good for printing to these printers. (https://github.com/mike42/escpos-php)
I read that this script prints locally on server machine or networked printer. But problem is, the printer I am using on the client side only support USB or serial/parallel. How do I send escpos character directly from server to client printer?
To be able access local USB deviced via the Webserver would be a huge security risk. Just think of a "evil" server that prints the whole wikipedia on any printer connected to a client, for example.
I don't think that there is a way to access any client-connected USB device with a simple web-based server software.
I would suggest either to
get a receipt printer that shows up as a regular printer and just
styling your receipts accordingly
write a Thick Client instead or
write a "print-agent" that regularly checks the server if there is any job for the locally connected receipt printer.
Either way, I do not think that, at this point, there is much use for PHP.
You could, of course, try tunneling USB via IP, but that would be quite a hassle to setup and maintain.
I know this reply may be too late but I will still leave my answer for anyone that will be needing this in the future.
You can setup a PHP script in your local machine which you can trigger in your remote app once a print button is pressed (maybe via a javascript window open which opens the URL of your local script). That PHP script contains code for printing your receipt using your local thermal printer. You can get the data via API from your remote app. This is somehow somehow a dirty solution but I think this is much safer instead of opening a port just for printing.

Website to computer communications

I am working on my senior project at university and I have a question. My advisor and other workers don't know much more on the matter so I thought I would toss it out to SO and see if you could help.
We want to make a website that will be hosted on a server that we are configuring. That website will have buttons on it, and when visitors of that website click a certain button we want to register an event on the server. We plan on doing this with PHP.
Once that event is registered (this is where we get lost), we want to communicate with a serial device on a remote computer. We are confident we can set up the PHP event/listener for the button press, but once we have that registered, how do we signal to the remote computer(connected via T1 line/routers) to communicate with the serial device? What is this sequence of events referred to as? The hardest thing for us (when researching it) is that we are not certain what to search for!
We have a feeling that a python script could be running on the server, get signals from the PHP listener, and then communicate with the remote PC. The remote PC could also be running a python script that then will communicate with our serial device. Again, most of this makes sense, but we are not clear on how we communicate between Python and PHP on the web server (or if this is possible).
If any one could give me some advice on what to search for, or similar projects I would really appreciate it. Thanks,
Both php and python can communicate via sockets, so I guess that is a good bet.
In PHP, when you receive the signal from the click button, open a socket to your python app with socket_create.
In python, you would need to implement a server socket (SocketServer) that listens for a connection.
Try reading up on sockets communication in general and socket programming in php and python specifically.
You can set up a web server also on the remote computer, perhaps using the same software as on the public server, so you do not need to learn another technology. The public server can make HTTP requests and the remote server responds by communicating with the serial device.

How to print to a printer installed on the server via php (Windows 2008)

Through an "intranet" application I need to be able to print precisely formatted pages to a printer that will be installed on the "web server".
For example, the user will access the application via their browser and when they complete a transaction a contract should print. The contract prints dynamic content on a pre-printed form (hence the precisely formatted requirement). This contract should print on a printer that is installed on a Windows Server 2008 machine, which is the same machine running the application.
I am using php as it is, so it would seem that it would be the best way to pull this off since both the printer and the php are running off the same box. Unfortunately, I haven't had much luck finding a good lpr (or other) print package.
Additionally, I need to print labels in the same manner (to a Zebra TLP 2844-z). However, I am fairly sure that if I can print to a printer using LPR it won't matter what type of printer it is.
Take a look at LPD, CUPS. Most likely you would need to convert your script output into PostScript then send it over to the printer.
http://php.net/manual/en/book.ps.php
If you can generate PDF (you can convert HTML into PDF)
exec cat generated.pdf | acroread -toPostScript | lpr -P $printer
Try also looking for help on serverfault.com

Categories