recreate project
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
Interfaces
|
||||
----------
|
||||
This directory contains boilerpalte code to show you how to open a print connector
|
||||
to printers which are connected in different ways.
|
||||
|
||||
To get a list of supported interfaces and operating systems, see the main README.md file for the project.
|
||||
|
||||
If you have a printer interface with no example, and you want to help put one together, then please lodge a request on the bug tracker: https://github.com/mike42/escpos-php/issues
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/* Change to the correct path if you copy this example! */
|
||||
require __DIR__ . '/../../vendor/autoload.php';
|
||||
use Mike42\Escpos\Printer;
|
||||
use Mike42\Escpos\PrintConnectors\CupsPrintConnector;
|
||||
|
||||
try {
|
||||
$connector = new CupsPrintConnector("EPSON_TM-T20");
|
||||
|
||||
/* Print a "Hello world" receipt" */
|
||||
$printer = new Printer($connector);
|
||||
$printer -> text("Hello World!\n");
|
||||
$printer -> cut();
|
||||
|
||||
/* Close printer */
|
||||
$printer -> close();
|
||||
} catch (Exception $e) {
|
||||
echo "Couldn't print to this printer: " . $e -> getMessage() . "\n";
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
/* Change to the correct path if you copy this example! */
|
||||
require __DIR__ . '/../../vendor/autoload.php';
|
||||
use Mike42\Escpos\Printer;
|
||||
use Mike42\Escpos\PrintConnectors\NetworkPrintConnector;
|
||||
|
||||
/* Most printers are open on port 9100, so you just need to know the IP
|
||||
* address of your receipt printer, and then fsockopen() it on that port.
|
||||
*/
|
||||
try {
|
||||
$connector = new NetworkPrintConnector("10.x.x.x", 9100);
|
||||
|
||||
/* Print a "Hello world" receipt" */
|
||||
$printer = new Printer($connector);
|
||||
$printer -> text("Hello World!\n");
|
||||
$printer -> cut();
|
||||
|
||||
/* Close printer */
|
||||
$printer -> close();
|
||||
} catch (Exception $e) {
|
||||
echo "Couldn't print to this printer: " . $e -> getMessage() . "\n";
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/* Change to the correct path if you copy this example! */
|
||||
require __DIR__ . '/../../vendor/autoload.php';
|
||||
use Mike42\Escpos\Printer;
|
||||
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
|
||||
|
||||
/**
|
||||
* On Linux, use the usblp module to make your printer available as a device
|
||||
* file. This is generally the default behaviour if you don't install any
|
||||
* vendor drivers.
|
||||
*
|
||||
* Once this is done, use a FilePrintConnector to open the device.
|
||||
*
|
||||
* Troubleshooting: On Debian, you must be in the lp group to access this file.
|
||||
* dmesg to see what happens when you plug in your printer to make sure no
|
||||
* other drivers are unloading the module.
|
||||
*/
|
||||
try {
|
||||
// Enter the device file for your USB printer here
|
||||
$connector = new FilePrintConnector("/dev/usb/lp0");
|
||||
//$connector = new FilePrintConnector("/dev/usb/lp1");
|
||||
//$connector = new FilePrintConnector("/dev/usb/lp2");
|
||||
|
||||
/* Print a "Hello world" receipt" */
|
||||
$printer = new Printer($connector);
|
||||
$printer -> text("Hello World!\n");
|
||||
$printer -> cut();
|
||||
|
||||
/* Close printer */
|
||||
$printer -> close();
|
||||
} catch (Exception $e) {
|
||||
echo "Couldn't print to this printer: " . $e -> getMessage() . "\n";
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/* Change to the correct path if you copy this example! */
|
||||
require __DIR__ . '/../../vendor/autoload.php';
|
||||
use Mike42\Escpos\Printer;
|
||||
use Mike42\Escpos\PrintConnectors\WindowsPrintConnector;
|
||||
|
||||
/**
|
||||
* Install the printer using USB printing support, and the "Generic / Text Only" driver,
|
||||
* then share it.
|
||||
*
|
||||
* Use a WindowsPrintConnector with the share name to print. This works on either
|
||||
* Windows or Linux.
|
||||
*
|
||||
* Troubleshooting: Fire up a command prompt/terminal, and ensure that (if your printer is
|
||||
* shared as "Receipt Printer"), the following commands work.
|
||||
*
|
||||
* Windows: (use an appropriate "net use" command if you need authentication)
|
||||
* echo "Hello World" > testfile
|
||||
* ## If you need authentication, use "net use" to hook up the printer:
|
||||
* # net use "\\computername\Receipt Printer" /user:Guest
|
||||
* # net use "\\computername\Receipt Printer" /user:Bob secret
|
||||
* # net use "\\computername\Receipt Printer" /user:workgroup\Bob secret
|
||||
* copy testfile "\\computername\Receipt Printer"
|
||||
* del testfile
|
||||
*
|
||||
* GNU/Linux:
|
||||
* # No authentication
|
||||
* echo "Hello World" | smbclient "//computername/Receipt Printer" -c "print -" -N
|
||||
* # Guest login
|
||||
* echo "Hello World" | smbclient "//computername/Receipt Printer" -U Guest -c "print -" -N
|
||||
* # Basic username/password
|
||||
* echo "Hello World" | smbclient "//computername/Receipt Printer" secret -U "Bob" -c "print -"
|
||||
* # Including domain name
|
||||
* echo "Hello World" | smbclient "//computername/Receipt Printer" secret -U "workgroup\\Bob" -c "print -"
|
||||
*/
|
||||
try {
|
||||
// Enter the share name for your printer here, as a smb:// url format
|
||||
$connector = new WindowsPrintConnector("smb://computername/Receipt Printer");
|
||||
//$connector = new WindowsPrintConnector("smb://Guest@computername/Receipt Printer");
|
||||
//$connector = new WindowsPrintConnector("smb://FooUser:secret@computername/workgroup/Receipt Printer");
|
||||
//$connector = new WindowsPrintConnector("smb://User:secret@computername/Receipt Printer");
|
||||
|
||||
/* Print a "Hello world" receipt" */
|
||||
$printer = new Printer($connector);
|
||||
$printer -> text("Hello World!\n");
|
||||
$printer -> cut();
|
||||
|
||||
/* Close printer */
|
||||
$printer -> close();
|
||||
} catch (Exception $e) {
|
||||
echo "Couldn't print to this printer: " . $e -> getMessage() . "\n";
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/* Change to the correct path if you copy this example! */
|
||||
require __DIR__ . '/../../vendor/autoload.php';
|
||||
use Mike42\Escpos\Printer;
|
||||
use Mike42\Escpos\PrintConnectors\WindowsPrintConnector;
|
||||
|
||||
/**
|
||||
* Assuming your printer is available at LPT1,
|
||||
* simpy instantiate a WindowsPrintConnector to it.
|
||||
*
|
||||
* When troubleshooting, make sure you can send it
|
||||
* data from the command-line first:
|
||||
* echo "Hello World" > LPT1
|
||||
*/
|
||||
try {
|
||||
$connector = new WindowsPrintConnector("LPT1");
|
||||
|
||||
// A FilePrintConnector will also work, but on non-Windows systems, writes
|
||||
// to an actual file called 'LPT1' rather than giving a useful error.
|
||||
// $connector = new FilePrintConnector("LPT1");
|
||||
|
||||
/* Print a "Hello world" receipt" */
|
||||
$printer = new Printer($connector);
|
||||
$printer -> text("Hello World!\n");
|
||||
$printer -> cut();
|
||||
|
||||
/* Close printer */
|
||||
$printer -> close();
|
||||
} catch (Exception $e) {
|
||||
echo "Couldn't print to this printer: " . $e -> getMessage() . "\n";
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/* Change to the correct path if you copy this example! */
|
||||
require __DIR__ . '/../../vendor/autoload.php';
|
||||
use Mike42\Escpos\Printer;
|
||||
use Mike42\Escpos\PrintConnectors\WindowsPrintConnector;
|
||||
|
||||
/**
|
||||
* Install the printer using USB printing support, and the "Generic / Text Only" driver,
|
||||
* then share it (you can use a firewall so that it can only be seen locally).
|
||||
*
|
||||
* Use a WindowsPrintConnector with the share name to print.
|
||||
*
|
||||
* Troubleshooting: Fire up a command prompt, and ensure that (if your printer is shared as
|
||||
* "Receipt Printer), the following commands work:
|
||||
*
|
||||
* echo "Hello World" > testfile
|
||||
* copy testfile "\\%COMPUTERNAME%\Receipt Printer"
|
||||
* del testfile
|
||||
*/
|
||||
try {
|
||||
// Enter the share name for your USB printer here
|
||||
$connector = null;
|
||||
//$connector = new WindowsPrintConnector("Receipt Printer");
|
||||
|
||||
/* Print a "Hello world" receipt" */
|
||||
$printer = new Printer($connector);
|
||||
$printer -> text("Hello World!\n");
|
||||
$printer -> cut();
|
||||
|
||||
/* Close printer */
|
||||
$printer -> close();
|
||||
} catch (Exception $e) {
|
||||
echo "Couldn't print to this printer: " . $e -> getMessage() . "\n";
|
||||
}
|
||||
Reference in New Issue
Block a user