recreate project
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
require __DIR__ . '/../../vendor/autoload.php';
|
||||
use Mike42\Escpos\Printer;
|
||||
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
|
||||
|
||||
$a = "{A012323392982";
|
||||
$b = "{B012323392982";
|
||||
$c = "{C" . chr(01) . chr(23) . chr(23) . chr(39) . chr(29) . chr(82);
|
||||
|
||||
$connector = new FilePrintConnector("php://stdout");
|
||||
$printer = new Printer($connector);
|
||||
$printer -> setJustification(Printer::JUSTIFY_CENTER);
|
||||
$printer -> setBarcodeHeight(48);
|
||||
$printer->setBarcodeTextPosition(Printer::BARCODE_TEXT_BELOW);
|
||||
foreach(array($a, $b, $c) as $item) {
|
||||
$printer -> barcode($item, Printer::BARCODE_CODE128);
|
||||
$printer -> feed(1);
|
||||
}
|
||||
$printer -> cut();
|
||||
$printer -> close();
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
require __DIR__ . '/../../vendor/autoload.php';
|
||||
use Mike42\Escpos\Printer;
|
||||
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
|
||||
|
||||
/**
|
||||
* This example shows how to send a custom command to the printer
|
||||
*
|
||||
* "ESC ( B" is the barcode function for Epson LX300 series.
|
||||
* This is not part of standard ESC/POS, but it's a good example
|
||||
* of how to send some binary to the driver.
|
||||
*/
|
||||
|
||||
/* Barcode type is used in this script */
|
||||
const EAN13 = 0;
|
||||
|
||||
/* Barcode properties */
|
||||
$type = EAN13;
|
||||
$content = "0075678164125";
|
||||
|
||||
/*
|
||||
* Make the command.
|
||||
* This is documented on page A-14 of:
|
||||
* https://files.support.epson.com/pdf/lx300p/lx300pu1.pdf
|
||||
*/
|
||||
$m = chr(EAN13);
|
||||
$n = intLowHigh(strlen($content), 2);
|
||||
$barcodeCommand = Printer::ESC . "G(" . $m . $n . $content;
|
||||
|
||||
/* Send it off as usual */
|
||||
$connector = new FilePrintConnector("php://output");
|
||||
$printer = new Printer($connector);
|
||||
$printer->getPrintConnector()->write($barcodeCommand);
|
||||
$printer->cut();
|
||||
$printer->close();
|
||||
|
||||
/**
|
||||
* Generate two characters for a number: In lower and higher parts, or more parts as needed.
|
||||
*
|
||||
* @param int $input
|
||||
* Input number
|
||||
* @param int $length
|
||||
* The number of bytes to output (1 - 4).
|
||||
*/
|
||||
function intLowHigh($input, $length)
|
||||
{
|
||||
$outp = "";
|
||||
for ($i = 0; $i < $length; $i ++) {
|
||||
$outp .= chr($input % 256);
|
||||
$input = (int) ($input / 256);
|
||||
}
|
||||
return $outp;
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/*
|
||||
* Example of one way you could load a PNG data URI into an EscposImage object
|
||||
* without using a file.
|
||||
*/
|
||||
require __DIR__ . '/../../vendor/autoload.php';
|
||||
use Mike42\Escpos\Printer;
|
||||
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
|
||||
use Mike42\Escpos\ImagickEscposImage;
|
||||
|
||||
// Data URI for a PNG image (red dot from https://en.wikipedia.org/wiki/Data_URI_scheme )
|
||||
$uri = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA
|
||||
AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
|
||||
9TXL0Y4OHwAAAABJRU5ErkJggg==";
|
||||
|
||||
// Convert data URI to binary data
|
||||
$imageBlob = base64_decode(explode(",", $uri)[1]);
|
||||
|
||||
// Give Imagick a filename with the correct extension to stop it from attempting
|
||||
// to identify the format itself (this avoids CVE-2016–3714)
|
||||
$imagick = new Imagick();
|
||||
$imagick -> setResourceLimit(6, 1); // Prevent libgomp1 segfaults, grumble grumble.
|
||||
$imagick -> readImageBlob($imageBlob, "input.png");
|
||||
|
||||
// Load Imagick straight into an EscposImage object
|
||||
$im = new ImagickEscposImage();
|
||||
$im -> readImageFromImagick($imagick);
|
||||
|
||||
// Do a test print to make sure that this EscposImage object has the right data
|
||||
// (should see a tiny bullet point)
|
||||
$connector = new FilePrintConnector("php://output");
|
||||
$printer = new Printer($connector);
|
||||
$printer -> bitImage($im);
|
||||
$printer -> cut();
|
||||
$printer -> close();
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/*
|
||||
* Example showing how to return binary data back to the user.
|
||||
*
|
||||
* This is intended for the "Star TSP650IIcloudPRNT" printer.
|
||||
*/
|
||||
require __DIR__ . '/../../vendor/autoload.php';
|
||||
use Mike42\Escpos\Printer;
|
||||
use Mike42\Escpos\PrintConnectors\DummyPrintConnector;
|
||||
use Mike42\Escpos\CapabilityProfile;
|
||||
|
||||
// Make sure you load a Star print connector or you may get gibberish.
|
||||
$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();
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
require __DIR__ . '/../../vendor/autoload.php';
|
||||
use Mike42\Escpos\CapabilityProfile;
|
||||
use Mike42\Escpos\Printer;
|
||||
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
|
||||
use Mike42\Escpos\PrintBuffers\ImagePrintBuffer;
|
||||
|
||||
/* This example shows the printing of Latvian text on the Star TUP 592 printer */
|
||||
$profile = CapabilityProfile::load("SP2000");
|
||||
|
||||
/* Option 1: Native character encoding */
|
||||
$connector = new FilePrintConnector("php://stdout");
|
||||
$printer = new Printer($connector, $profile);
|
||||
$printer -> text("Glāžšķūņa rūķīši dzērumā čiepj Baha koncertflīģeļu vākus\n");
|
||||
$printer -> cut();
|
||||
$printer -> close();
|
||||
|
||||
/* Option 2: Image-based output (formatting not available using this output) */
|
||||
$buffer = new ImagePrintBuffer();
|
||||
$connector = new FilePrintConnector("php://stdout");
|
||||
$printer = new Printer($connector, $profile);
|
||||
$printer -> setPrintBuffer($buffer);
|
||||
$printer -> text("Glāžšķūņa rūķīši dzērumā čiepj Baha koncertflīģeļu vākus\n");
|
||||
$printer -> cut();
|
||||
$printer -> close();
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
require __DIR__ . '/../../vendor/autoload.php';
|
||||
use Mike42\Escpos\CapabilityProfile;
|
||||
use Mike42\Escpos\Printer;
|
||||
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
|
||||
|
||||
/*
|
||||
* This example shows how tok send a custom command to the printer-
|
||||
* The use case here is an Epson TM-T20II and German text.
|
||||
*
|
||||
* Background: Not all ESC/POS features are available in the driver, so sometimes
|
||||
* you might want to send a custom commnad. This is useful for testing
|
||||
* new features.
|
||||
*
|
||||
* The Escpos::text() function removes non-printable characters as a precaution,
|
||||
* so that commands cannot be injected into user input. To send raw data to
|
||||
* the printer, you need to write bytes to the underlying PrintConnector.
|
||||
*
|
||||
* If you get a new command working, please file an issue on GitHub with a code
|
||||
* snippet so that it can be incorporated into escpos-php.
|
||||
*/
|
||||
|
||||
/* Set up profile & connector */
|
||||
$connector = new FilePrintConnector("php://output");
|
||||
$profile = CapabilityProfile::load("default"); // Works for Epson printers
|
||||
|
||||
$printer = new Printer($connector, $profile);
|
||||
$cmd = Printer::ESC . "V" . chr(1); // Try out 90-degree rotation.
|
||||
$printer -> getPrintConnector() -> write($cmd);
|
||||
$printer -> text("Beispieltext in Deutsch\n");
|
||||
$printer -> cut();
|
||||
$printer -> close();
|
||||
/*
|
||||
* Hex-dump of output confirms that ESC V 1 being sent:
|
||||
*
|
||||
* 0000000 033 @ 033 V 001 B e i s p i e l t e x
|
||||
* 0000010 t i n D e u t s c h \n 035 V A
|
||||
* 0000020 003
|
||||
*/
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/*
|
||||
* Example of printing Spanish text on SEYPOS PRP-300 thermal line printer.
|
||||
* The characters in Spanish are available in code page 437, so no special
|
||||
* code pages are needed in this case (SimpleCapabilityProfile).
|
||||
*
|
||||
* Use the hardware switch to activate "Two-byte Character Code"
|
||||
*/
|
||||
require __DIR__ . '/../../vendor/autoload.php';
|
||||
use Mike42\Escpos\CapabilityProfile;
|
||||
use Mike42\Escpos\Printer;
|
||||
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
|
||||
|
||||
$connector = new FilePrintConnector("php://output");
|
||||
$profile = CapabilityProfile::load("simple"); // Works for Epson printers
|
||||
$printer = new Printer($connector);
|
||||
$printer -> text("El pingüino Wenceslao hizo kilómetros bajo exhaustiva lluvia y frío, añoraba a su querido cachorro.\n");
|
||||
$printer -> cut();
|
||||
$printer -> close();
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
/*
|
||||
* This is an example of printing chinese text. This is a bit different to other character encodings, because
|
||||
* the printer accepts a 2-byte character encoding (GBK), and formatting is handled differently while in this mode.
|
||||
*
|
||||
* At the time of writing, this is implemented separately as a textChinese() function, until chinese text
|
||||
* can be properly detected and printed alongside other encodings.
|
||||
*/
|
||||
require __DIR__ . '/../../vendor/autoload.php';
|
||||
use Mike42\Escpos\CapabilityProfile;
|
||||
use Mike42\Escpos\Printer;
|
||||
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
|
||||
|
||||
$connector = new FilePrintConnector("/dev/usb/lp1");
|
||||
$profile = CapabilityProfile::load("default");
|
||||
|
||||
$printer = new Printer($connector);
|
||||
|
||||
// Example text from #37
|
||||
$printer -> textChinese("艾德蒙 AOC E2450SWH 23.6吋 LED液晶寬螢幕特價$ 19900\n\n");
|
||||
|
||||
// Note that on the printer tested (ZJ5890), the font only contained simplified characters.
|
||||
$printer -> textChinese("示例文本打印机!\n\n");
|
||||
$printer -> close();
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
require __DIR__ . '/../../vendor/autoload.php';
|
||||
use Mike42\Escpos\CapabilityProfile;
|
||||
use Mike42\Escpos\Printer;
|
||||
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
|
||||
use Mike42\Escpos\PrintBuffers\ImagePrintBuffer;
|
||||
|
||||
$profile = CapabilityProfile::load("default");
|
||||
// This is a quick demo of currency symbol issues in #39.
|
||||
|
||||
/* Option 1: Native ESC/POS characters, depends on printer and is buggy. */
|
||||
$connector = new FilePrintConnector("php://stdout");
|
||||
$printer = new Printer($connector, $profile);
|
||||
$printer -> text("€ 9,95\n");
|
||||
$printer -> text("£ 9.95\n");
|
||||
$printer -> text("$ 9.95\n");
|
||||
$printer -> text("¥ 9.95\n");
|
||||
$printer -> cut();
|
||||
$printer -> close();
|
||||
|
||||
/* Option 2: Image-based output (formatting not available using this output). */
|
||||
$buffer = new ImagePrintBuffer();
|
||||
$connector = new FilePrintConnector("php://stdout");
|
||||
$printer = new Printer($connector, $profile);
|
||||
$printer -> setPrintBuffer($buffer);
|
||||
$printer -> text("€ 9,95\n");
|
||||
$printer -> text("£ 9.95\n");
|
||||
$printer -> text("$ 9.95\n");
|
||||
$printer -> text("¥ 9.95\n");
|
||||
$printer -> cut();
|
||||
$printer -> close();
|
||||
|
||||
/*
|
||||
Option 3: If the printer is configured to print in a specific code
|
||||
page, you can set up a CapabilityProfile which either references its
|
||||
iconv encoding name, or includes all of the available characters.
|
||||
|
||||
Here, we make use of CP858 for its inclusion of currency symbols which
|
||||
are not available in CP437. CP858 has good printer support, but is not
|
||||
included in all iconv builds.
|
||||
*/
|
||||
class CustomCapabilityProfile extends CapabilityProfile
|
||||
{
|
||||
function getCustomCodePages()
|
||||
{
|
||||
/*
|
||||
* Example to print in a specific, user-defined character set
|
||||
* on a printer which has been configured to use i
|
||||
*/
|
||||
return array(
|
||||
'CP858' => "ÇüéâäàåçêëèïîìÄÅ" .
|
||||
"ÉæÆôöòûùÿÖÜø£Ø×ƒ" .
|
||||
"áíóúñѪº¿®¬½¼¡«»" .
|
||||
"░▒▓│┤ÁÂÀ©╣║╗╝¢¥┐" .
|
||||
"└┴┬├─┼ãÃ╚╔╩╦╠═╬¤" .
|
||||
"ðÐÊËÈ€ÍÎÏ┘┌█▄¦Ì▀" .
|
||||
"ÓßÔÒõÕµþÞÚÛÙýݯ´" .
|
||||
" ±‗¾¶§÷¸°¨·¹³²■ ");
|
||||
}
|
||||
|
||||
function getSupportedCodePages()
|
||||
{
|
||||
return array(
|
||||
0 => 'custom:CP858');
|
||||
}
|
||||
}
|
||||
|
||||
$connector = new FilePrintConnector("php://stdout");
|
||||
$profile = CustomCapabilityProfile::getInstance();
|
||||
$printer = new Printer($connector, $profile);
|
||||
$printer -> text("€ 9,95\n");
|
||||
$printer -> text("£ 9.95\n");
|
||||
$printer -> text("$ 9.95\n");
|
||||
$printer -> text("¥ 9.95\n");
|
||||
|
||||
$printer -> cut();
|
||||
$printer -> close();
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/* Example of printing the GBP pound symbol on a STAR TSP650
|
||||
*
|
||||
* In this example, it's shown how to check that your PHP files are actually being
|
||||
* saved in unicode. Sections B) and C) are identical in UTF-8, but different
|
||||
* if you are saving to a retro format like Windows-1252.
|
||||
*/
|
||||
|
||||
// Adjust these to your environment
|
||||
require __DIR__ . '/../../vendor/autoload.php';
|
||||
use Mike42\Escpos\CapabilityProfile;
|
||||
use Mike42\Escpos\Printer;
|
||||
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
|
||||
|
||||
$connector = new FilePrintConnector("php://stdout");
|
||||
|
||||
// Start printer
|
||||
$profile = CapabilityProfile::load("simple");
|
||||
$printer = new Printer($connector, $profile);
|
||||
|
||||
// A) Raw pound symbol
|
||||
// This is the most likely thing to work, and bypasses all the fancy stuff.
|
||||
$printer -> textRaw("\x9C"); // based on position in CP437
|
||||
$printer -> text(" 1.95\n");
|
||||
|
||||
// B) Manually encoded UTF8 pound symbol. Tests that the driver correctly
|
||||
// encodes this as CP437.
|
||||
$printer -> text(base64_decode("wqM=") . " 2.95\n");
|
||||
|
||||
// C) Pasted in file. Tests that your files are being saved as UTF-8, which
|
||||
// escpos-php is able to convert automatically to a mix of code pages.
|
||||
$printer -> text("£ 3.95\n");
|
||||
|
||||
$printer -> cut();
|
||||
$printer -> close();
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/* Example of Greek text on the P-822D */
|
||||
require __DIR__ . '/../../vendor/autoload.php';
|
||||
use Mike42\Escpos\CapabilityProfile;
|
||||
use Mike42\Escpos\Printer;
|
||||
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
|
||||
|
||||
// Setup the printer
|
||||
$connector = new FilePrintConnector("php://stdout");
|
||||
$profile = CapabilityProfile::load("P822D");
|
||||
$printer = new Printer($connector, $profile);
|
||||
|
||||
// Print a Greek pangram
|
||||
$text = "Ξεσκεπάζω την ψυχοφθόρα βδελυγμία";
|
||||
$printer -> text($text . "\n");
|
||||
$printer -> cut();
|
||||
|
||||
// Close the connection
|
||||
$printer -> close();
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/*
|
||||
* Example of calling ImageMagick 'convert' to manipulate an image prior to printing.
|
||||
*
|
||||
* Written as an example to remind you to do four things-
|
||||
* - escape your command-line arguments with escapeshellarg
|
||||
* - close the printer
|
||||
* - delete any temp files
|
||||
* - detect and handle external command failure
|
||||
*
|
||||
* Note that image operations are slow. You can and should serialise an EscposImage
|
||||
* object into some sort of cache if you will re-use the output.
|
||||
*/
|
||||
require __DIR__ . '/../../vendor/autoload.php';
|
||||
use Mike42\Escpos\CapabilityProfile;
|
||||
use Mike42\Escpos\Printer;
|
||||
use Mike42\Escpos\EscposImage;
|
||||
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
|
||||
|
||||
// Paths to images to combine
|
||||
$img1_path = dirname(__FILE__) . "/../resources/tux.png";
|
||||
$img2_path = dirname(__FILE__) . "/../resources/escpos-php.png";
|
||||
|
||||
// Set up temp file with .png extension
|
||||
$tmpf_path = tempnam(sys_get_temp_dir(), 'escpos-php');
|
||||
$imgCombined_path = $tmpf_path . ".png";
|
||||
|
||||
try {
|
||||
// Convert, load image, remove temp files
|
||||
$cmd = sprintf(
|
||||
"convert %s %s +append %s",
|
||||
escapeshellarg($img1_path),
|
||||
escapeshellarg($img2_path),
|
||||
escapeshellarg($imgCombined_path)
|
||||
);
|
||||
exec($cmd, $outp, $retval);
|
||||
if ($retval != 0) {
|
||||
// Detect and handle command failure
|
||||
throw new Exception("Command \"$cmd\" returned $retval." . implode("\n", $outp));
|
||||
}
|
||||
$img = EscposImage::load($imgCombined_path);
|
||||
|
||||
// Setup the printer
|
||||
$connector = new FilePrintConnector("php://stdout");
|
||||
$profile = CapabilityProfile::load("default");
|
||||
|
||||
// Run the actual print
|
||||
$printer = new Printer($connector, $profile);
|
||||
try {
|
||||
$printer -> setJustification(Printer::JUSTIFY_CENTER);
|
||||
$printer -> graphics($img);
|
||||
$printer -> cut();
|
||||
} finally {
|
||||
// Always close the connection
|
||||
$printer -> close();
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
// Print out any errors: Eg. printer connection, image loading & external image manipulation.
|
||||
echo $e -> getMessage() . "\n";
|
||||
echo $e -> getTraceAsString();
|
||||
} finally {
|
||||
unlink($imgCombined_path);
|
||||
unlink($tmpf_path);
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
/*
|
||||
* This example shows Arabic image-based output on the EPOS TEP 220m.
|
||||
*
|
||||
* Because escpos-php is not yet able to render Arabic correctly
|
||||
* on thermal line printers, small images are generated and sent
|
||||
* instead. This is a bit slower, and only limited formatting
|
||||
* is currently available in this mode.
|
||||
*
|
||||
* Requirements are:
|
||||
* - imagick extension (For the ImagePrintBuffer, which does not
|
||||
* support gd at the time of writing)
|
||||
* - ArPHP 4.0 (release date: Jan 8, 2016), available from SourceForge, for
|
||||
* handling the layout for this example.
|
||||
*/
|
||||
require __DIR__ . '/../../vendor/autoload.php';
|
||||
use Mike42\Escpos\CapabilityProfile;
|
||||
use Mike42\Escpos\Printer;
|
||||
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
|
||||
use Mike42\Escpos\PrintBuffers\ImagePrintBuffer;
|
||||
|
||||
/*
|
||||
* Drop Ar-php into the folder listed below:
|
||||
*/
|
||||
require_once(dirname(__FILE__) . "/../../I18N/Arabic.php");
|
||||
$fontPath = dirname(__FILE__) . "/../../I18N/Arabic/Examples/GD/ae_AlHor.ttf";
|
||||
|
||||
/*
|
||||
* Inputs are some text, line wrapping options, and a font size.
|
||||
*/
|
||||
$textUtf8 = "صِف خَلقَ خَودِ كَمِثلِ الشَمسِ إِذ بَزَغَت — يَحظى الضَجيعُ بِها نَجلاءَ مِعطارِ";
|
||||
$maxChars = 50;
|
||||
$fontSize = 28;
|
||||
|
||||
/*
|
||||
* First, convert the text into LTR byte order with line wrapping,
|
||||
* Using the Ar-PHP library.
|
||||
*
|
||||
* The Ar-PHP library uses the default internal encoding, and can print
|
||||
* a lot of errors depending on the input, so be prepared to debug
|
||||
* the next four lines.
|
||||
*
|
||||
* Note that this output shows that numerals are converted to placeholder
|
||||
* characters, indicating that western numerals (123) have to be used instead.
|
||||
*/
|
||||
mb_internal_encoding("UTF-8");
|
||||
$Arabic = new I18N_Arabic('Glyphs');
|
||||
$textLtr = $Arabic -> utf8Glyphs($textUtf8, $maxChars);
|
||||
$textLine = explode("\n", $textLtr);
|
||||
|
||||
/*
|
||||
* Set up and use an image print buffer with a suitable font
|
||||
*/
|
||||
$buffer = new ImagePrintBuffer();
|
||||
$buffer -> setFont($fontPath);
|
||||
$buffer -> setFontSize($fontSize);
|
||||
|
||||
$profile = CapabilityProfile::load("TEP-200M");
|
||||
$connector = new FilePrintConnector("php://output");
|
||||
// = new WindowsPrintConnector("LPT2");
|
||||
// Windows LPT2 was used in the bug tracker
|
||||
|
||||
$printer = new Printer($connector, $profile);
|
||||
$printer -> setPrintBuffer($buffer);
|
||||
|
||||
$printer -> setJustification(Printer::JUSTIFY_RIGHT);
|
||||
foreach($textLine as $text) {
|
||||
// Print each line separately. We need to do this since Imagick thinks
|
||||
// text is left-to-right
|
||||
$printer -> text($text . "\n");
|
||||
}
|
||||
|
||||
$printer -> cut();
|
||||
$printer -> close();
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
require __DIR__ . '/../../vendor/autoload.php';
|
||||
use Mike42\Escpos\Printer;
|
||||
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
|
||||
use Mike42\Escpos\CapabilityProfile;
|
||||
|
||||
$connector = new FilePrintConnector("php://stdout");
|
||||
$profile = CapabilityProfile::load("default");
|
||||
$printer = new Printer($connector, $profile);
|
||||
|
||||
$printer -> text("Μιχάλης Νίκος\n");
|
||||
$printer -> cut();
|
||||
$printer -> close();
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
/*
|
||||
* Example of two-color printing, tested on an epson TM-U220 with two-color ribbon installed.
|
||||
*/
|
||||
require __DIR__ . '/../../vendor/autoload.php';
|
||||
use Mike42\Escpos\Printer;
|
||||
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
|
||||
|
||||
$connector = new FilePrintConnector("/dev/usb/lp0");
|
||||
$printer = new Printer($connector);
|
||||
try {
|
||||
$printer -> text("Hello World!\n");
|
||||
$printer -> setColor(Printer::COLOR_2);
|
||||
$printer -> text("Red?!\n");
|
||||
$printer -> setColor(Printer::COLOR_1);
|
||||
$printer -> text("Default color again?!\n");
|
||||
$printer -> cut();
|
||||
} finally {
|
||||
/* Always close the printer! */
|
||||
$printer -> close();
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/*
|
||||
* Example of dithering used in EscposImage by default, if you have Imagick loaded.
|
||||
*/
|
||||
require __DIR__ . '/../../vendor/autoload.php';
|
||||
use Mike42\Escpos\Printer;
|
||||
use Mike42\Escpos\EscposImage;
|
||||
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
|
||||
|
||||
$connector = new FilePrintConnector("/dev/usb/lp0");
|
||||
$printer = new Printer($connector);
|
||||
try {
|
||||
/* Load with optimisations enabled. If you have Imagick, this will get you
|
||||
a nicely dithered image, which prints very quickly
|
||||
*/
|
||||
$img1 = EscposImage::load(__DIR__ . '/../resources/tulips.png');
|
||||
$printer -> bitImage($img1);
|
||||
|
||||
/* Load with optimisations disabled, forcing the use of PHP to convert the
|
||||
pixels, which uses a threshold and is much slower.
|
||||
*/
|
||||
$img2 = EscposImage::load(__DIR__ . '/../resources/tulips.png', false);
|
||||
$printer -> bitImage($img2);
|
||||
$printer -> cut();
|
||||
} finally {
|
||||
/* Always close the printer! */
|
||||
$printer -> close();
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
Specific examples
|
||||
-----------------
|
||||
|
||||
These examples are designed for specific combinations of language,
|
||||
printer and interface.
|
||||
|
||||
They are documented here because the general examples all set up the printer in a similar way.
|
||||
Reference in New Issue
Block a user