32-german-tm-t20-ii-custom-command.php 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. require __DIR__ . '/../../vendor/autoload.php';
  3. use Mike42\Escpos\CapabilityProfile;
  4. use Mike42\Escpos\Printer;
  5. use Mike42\Escpos\PrintConnectors\FilePrintConnector;
  6. /*
  7. * This example shows how tok send a custom command to the printer-
  8. * The use case here is an Epson TM-T20II and German text.
  9. *
  10. * Background: Not all ESC/POS features are available in the driver, so sometimes
  11. * you might want to send a custom commnad. This is useful for testing
  12. * new features.
  13. *
  14. * The Escpos::text() function removes non-printable characters as a precaution,
  15. * so that commands cannot be injected into user input. To send raw data to
  16. * the printer, you need to write bytes to the underlying PrintConnector.
  17. *
  18. * If you get a new command working, please file an issue on GitHub with a code
  19. * snippet so that it can be incorporated into escpos-php.
  20. */
  21. /* Set up profile & connector */
  22. $connector = new FilePrintConnector("php://output");
  23. $profile = CapabilityProfile::load("default"); // Works for Epson printers
  24. $printer = new Printer($connector, $profile);
  25. $cmd = Printer::ESC . "V" . chr(1); // Try out 90-degree rotation.
  26. $printer -> getPrintConnector() -> write($cmd);
  27. $printer -> text("Beispieltext in Deutsch\n");
  28. $printer -> cut();
  29. $printer -> close();
  30. /*
  31. * Hex-dump of output confirms that ESC V 1 being sent:
  32. *
  33. * 0000000 033 @ 033 V 001 B e i s p i e l t e x
  34. * 0000010 t i n D e u t s c h \n 035 V A
  35. * 0000020 003
  36. */