6-arabic-epos-tep-220m.php 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /*
  3. * This example shows Arabic image-based output on the EPOS TEP 220m.
  4. *
  5. * Because escpos-php is not yet able to render Arabic correctly
  6. * on thermal line printers, small images are generated and sent
  7. * instead. This is a bit slower, and only limited formatting
  8. * is currently available in this mode.
  9. *
  10. * Requirements are:
  11. * - imagick extension (For the ImagePrintBuffer, which does not
  12. * support gd at the time of writing)
  13. * - ArPHP 4.0 (release date: Jan 8, 2016), available from SourceForge, for
  14. * handling the layout for this example.
  15. */
  16. require __DIR__ . '/../../vendor/autoload.php';
  17. use Mike42\Escpos\CapabilityProfile;
  18. use Mike42\Escpos\Printer;
  19. use Mike42\Escpos\PrintConnectors\FilePrintConnector;
  20. use Mike42\Escpos\PrintBuffers\ImagePrintBuffer;
  21. /*
  22. * Drop Ar-php into the folder listed below:
  23. */
  24. require_once(dirname(__FILE__) . "/../../I18N/Arabic.php");
  25. $fontPath = dirname(__FILE__) . "/../../I18N/Arabic/Examples/GD/ae_AlHor.ttf";
  26. /*
  27. * Inputs are some text, line wrapping options, and a font size.
  28. */
  29. $textUtf8 = "صِف خَلقَ خَودِ كَمِثلِ الشَمسِ إِذ بَزَغَت — يَحظى الضَجيعُ بِها نَجلاءَ مِعطارِ";
  30. $maxChars = 50;
  31. $fontSize = 28;
  32. /*
  33. * First, convert the text into LTR byte order with line wrapping,
  34. * Using the Ar-PHP library.
  35. *
  36. * The Ar-PHP library uses the default internal encoding, and can print
  37. * a lot of errors depending on the input, so be prepared to debug
  38. * the next four lines.
  39. *
  40. * Note that this output shows that numerals are converted to placeholder
  41. * characters, indicating that western numerals (123) have to be used instead.
  42. */
  43. mb_internal_encoding("UTF-8");
  44. $Arabic = new I18N_Arabic('Glyphs');
  45. $textLtr = $Arabic -> utf8Glyphs($textUtf8, $maxChars);
  46. $textLine = explode("\n", $textLtr);
  47. /*
  48. * Set up and use an image print buffer with a suitable font
  49. */
  50. $buffer = new ImagePrintBuffer();
  51. $buffer -> setFont($fontPath);
  52. $buffer -> setFontSize($fontSize);
  53. $profile = CapabilityProfile::load("TEP-200M");
  54. $connector = new FilePrintConnector("php://output");
  55. // = new WindowsPrintConnector("LPT2");
  56. // Windows LPT2 was used in the bug tracker
  57. $printer = new Printer($connector, $profile);
  58. $printer -> setPrintBuffer($buffer);
  59. $printer -> setJustification(Printer::JUSTIFY_RIGHT);
  60. foreach($textLine as $text) {
  61. // Print each line separately. We need to do this since Imagick thinks
  62. // text is left-to-right
  63. $printer -> text($text . "\n");
  64. }
  65. $printer -> cut();
  66. $printer -> close();