character-encodings-with-images.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /* Change to the correct path if you copy this example! */
  3. require_once(dirname(__FILE__) . "/../Escpos.php");
  4. /**
  5. * This example builds on character-encodings.php, also providing an image-based rendering.
  6. * This is quite slow, since a) the buffers are changed dozens of
  7. * times in the example, and b) It involves sending very wide images, which printers don't like!
  8. *
  9. * There are currently no test cases around the image printing, since it is an experimental feature.
  10. *
  11. * It does, however, illustrate the way that more encodings are available when image output is used.
  12. */
  13. include(dirname(__FILE__) . '/resources/character-encoding-test-strings.inc');
  14. try {
  15. // Enter connector and capability profile
  16. $connector = new FilePrintConnector("php://stdout");
  17. $profile = DefaultCapabilityProfile::getInstance();
  18. $buffers = array(new EscposPrintBuffer(), new ImagePrintBuffer());
  19. /* Print a series of receipts containing i18n example strings */
  20. $printer = new Escpos($connector, $profile);
  21. $printer -> selectPrintMode(Escpos::MODE_DOUBLE_HEIGHT | Escpos::MODE_EMPHASIZED | Escpos::MODE_DOUBLE_WIDTH);
  22. $printer -> text("Implemented languages\n");
  23. $printer -> selectPrintMode();
  24. foreach($inputsOk as $label => $str) {
  25. $printer -> setEmphasis(true);
  26. $printer -> text($label . ":\n");
  27. $printer -> setEmphasis(false);
  28. foreach($buffers as $buffer) {
  29. $printer -> setPrintBuffer($buffer);
  30. $printer -> text($str);
  31. }
  32. $printer -> setPrintBuffer($buffers[0]);
  33. }
  34. $printer -> feed();
  35. $printer -> selectPrintMode(Escpos::MODE_DOUBLE_HEIGHT | Escpos::MODE_EMPHASIZED | Escpos::MODE_DOUBLE_WIDTH);
  36. $printer -> text("Works in progress\n");
  37. $printer -> selectPrintMode();
  38. foreach($inputsNotOk as $label => $str) {
  39. $printer -> setEmphasis(true);
  40. $printer -> text($label . ":\n");
  41. $printer -> setEmphasis(false);
  42. foreach($buffers as $buffer) {
  43. $printer -> setPrintBuffer($buffer);
  44. $printer -> text($str);
  45. }
  46. $printer -> setPrintBuffer($buffers[0]);
  47. }
  48. $printer -> cut();
  49. /* Close printer */
  50. $printer -> close();
  51. } catch(Exception $e) {
  52. echo "Couldn't print to this printer: " . $e -> getMessage() . "\n";
  53. }