Reputation: 7154
I have a website (on a remote server)and this is viewed by the user on the iPhone (Safari).
I'm trying to achieve the user being able to print a text file from that site to a POS Printer (REGO Thermal Printer, RG-MTP58B). This printer does not support AirPrint but is a wifi printer and lives on 172.20.10.2:9100
IP and port.
As far as I understand I cannot directly print from the server as the Printer is not in the server network but local network.
I'm using this package: https://github.com/mike42/escpos-php as I see is the only still maintained.
I've tried this way:
$connector = new FilePrintConnector("php://stdout");
$printer = new Printer($connector);
$printer->text("Hello World!\n");
$printer->cut();
$printer->close();
But this just gives a white page and the printer does not receive anything.
I've tried saving the file in the server, open it in Safari but Safari doesn't provide an option to print it (not even in the "Share" area).
So i found out the package Author does this:
$connector = new DummyPrintConnector();
$profile = CapabilityProfile::load("TSP600");
$printer = new Printer($connector);
$printer->text("Hello world!\n");
$printer->cut();
// Get the data out as a string
$data = $connector->getData();
// Return it, check the manual for specifics.
header('Content-type: application/octet-stream');
header('Content-Length: '.strlen($data));
echo $data;
// Close the printer when done.
$printer->close();
(original code: here)
In this case it creates a file and it shows it like this:
Again it does not provide an option to print it (not even in the "Share" area).
The file content is a binary:
<0x1b>@Hello world!
<0x1d>VA<0x03>
How do I send this data to the printer?
Upvotes: 0
Views: 2510
Reputation: 86
Here is one possible solution is to create a simple app that is has a webview component that opens the URL to your server website.
Make a simple webview app for iPhone. You could use a wkwebview to your server see wkwebview
Read Receipt content from the webview and parse out the receipt.
-- Be sure to format the receipt text using Esc/POS codes to format text, feed lines and cut paper. Almost every receipt printer uses Esc/POS codes and many low cost thermal receipt printers like this actually use a Seiko Epson Corporation (SEC) engine. That is why this PHP code likely works well with many printers.
Use Direct Socket connection to the printer on the local network from the iPhone app. This way you can make sure that both the phone and the printer are on the same network.
If you are not a fan of swift, it is also possible to create the app with Xamarin or Apache Cordova as well as others.
Upvotes: 2
Reputation: 7154
I contacted the Printer (Rego Printer) manufacturer and basically they don't allow external connection, this means you must print locally.
Upvotes: 0