39-currency-symbols.php 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. use Mike42\Escpos\PrintBuffers\ImagePrintBuffer;
  7. $profile = CapabilityProfile::load("default");
  8. // This is a quick demo of currency symbol issues in #39.
  9. /* Option 1: Native ESC/POS characters, depends on printer and is buggy. */
  10. $connector = new FilePrintConnector("php://stdout");
  11. $printer = new Printer($connector, $profile);
  12. $printer -> text("€ 9,95\n");
  13. $printer -> text("£ 9.95\n");
  14. $printer -> text("$ 9.95\n");
  15. $printer -> text("¥ 9.95\n");
  16. $printer -> cut();
  17. $printer -> close();
  18. /* Option 2: Image-based output (formatting not available using this output). */
  19. $buffer = new ImagePrintBuffer();
  20. $connector = new FilePrintConnector("php://stdout");
  21. $printer = new Printer($connector, $profile);
  22. $printer -> setPrintBuffer($buffer);
  23. $printer -> text("€ 9,95\n");
  24. $printer -> text("£ 9.95\n");
  25. $printer -> text("$ 9.95\n");
  26. $printer -> text("¥ 9.95\n");
  27. $printer -> cut();
  28. $printer -> close();
  29. /*
  30. Option 3: If the printer is configured to print in a specific code
  31. page, you can set up a CapabilityProfile which either references its
  32. iconv encoding name, or includes all of the available characters.
  33. Here, we make use of CP858 for its inclusion of currency symbols which
  34. are not available in CP437. CP858 has good printer support, but is not
  35. included in all iconv builds.
  36. */
  37. class CustomCapabilityProfile extends CapabilityProfile
  38. {
  39. function getCustomCodePages()
  40. {
  41. /*
  42. * Example to print in a specific, user-defined character set
  43. * on a printer which has been configured to use i
  44. */
  45. return array(
  46. 'CP858' => "ÇüéâäàåçêëèïîìÄÅ" .
  47. "ÉæÆôöòûùÿÖÜø£Ø×ƒ" .
  48. "áíóúñѪº¿®¬½¼¡«»" .
  49. "░▒▓│┤ÁÂÀ©╣║╗╝¢¥┐" .
  50. "└┴┬├─┼ãÃ╚╔╩╦╠═╬¤" .
  51. "ðÐÊËÈ€ÍÎÏ┘┌█▄¦Ì▀" .
  52. "ÓßÔÒõÕµþÞÚÛÙýݯ´" .
  53. " ±‗¾¶§÷¸°¨·¹³²■ ");
  54. }
  55. function getSupportedCodePages()
  56. {
  57. return array(
  58. 0 => 'custom:CP858');
  59. }
  60. }
  61. $connector = new FilePrintConnector("php://stdout");
  62. $profile = CustomCapabilityProfile::getInstance();
  63. $printer = new Printer($connector, $profile);
  64. $printer -> text("€ 9,95\n");
  65. $printer -> text("£ 9.95\n");
  66. $printer -> text("$ 9.95\n");
  67. $printer -> text("¥ 9.95\n");
  68. $printer -> cut();
  69. $printer -> close();