margins-and-spacing.php 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /* Left margin & page width demo. */
  3. require __DIR__ . '/../vendor/autoload.php';
  4. use Mike42\Escpos\Printer;
  5. use Mike42\Escpos\PrintConnectors\FilePrintConnector;
  6. $connector = new FilePrintConnector("php://stdout"); // Add connector for your printer here.
  7. $printer = new Printer($connector);
  8. /* Line spacing */
  9. /*
  10. $printer -> setEmphasis(true);
  11. $printer -> text("Line spacing\n");
  12. $printer -> setEmphasis(false);
  13. foreach(array(16, 32, 64, 128, 255) as $spacing) {
  14. $printer -> setLineSpacing($spacing);
  15. $printer -> text("Spacing $spacing: The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.\n");
  16. }
  17. $printer -> setLineSpacing(); // Back to default
  18. */
  19. /* Stuff around with left margin */
  20. $printer -> setEmphasis(true);
  21. $printer -> text("Left margin\n");
  22. $printer -> setEmphasis(false);
  23. $printer -> text("Default left\n");
  24. foreach(array(1, 2, 4, 8, 16, 32, 64, 128, 256, 512) as $margin) {
  25. $printer -> setPrintLeftMargin($margin);
  26. $printer -> text("left margin $margin\n");
  27. }
  28. /* Reset left */
  29. $printer -> setPrintLeftMargin(0);
  30. /* Stuff around with page width */
  31. $printer -> setEmphasis(true);
  32. $printer -> text("Page width\n");
  33. $printer -> setEmphasis(false);
  34. $printer -> setJustification(Printer::JUSTIFY_RIGHT);
  35. $printer -> text("Default width\n");
  36. foreach(array(512, 256, 128, 64) as $width) {
  37. $printer -> setPrintWidth($width);
  38. $printer -> text("page width $width\n");
  39. }
  40. /* Printer shutdown */
  41. $printer -> cut();
  42. $printer -> close();