Copyright (c) 2014-2015 Michael Billington , incorporating modifications by: - Roni Saha - Gergely Radics - Warren Doyle Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. This class renders text to small images on-the-fly. It attempts to mimic the behaviour of text output, whilst supporting any fonts & character encodings which your system can handle. This class currently requires Imagick.
Inheritance: implements Mike42\Escpos\PrintBuffers\PrintBuffer
 * 
 * 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 = EposTepCapabilityProfile::getInstance();
$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();