windows-lpt.php 982B

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. /* Change to the correct path if you copy this example! */
  3. require __DIR__ . '/../../autoload.php';
  4. use Mike42\Escpos\Printer;
  5. use Mike42\Escpos\PrintConnectors\WindowsPrintConnector;
  6. /**
  7. * Assuming your printer is available at LPT1,
  8. * simpy instantiate a WindowsPrintConnector to it.
  9. *
  10. * When troubleshooting, make sure you can send it
  11. * data from the command-line first:
  12. * echo "Hello World" > LPT1
  13. */
  14. try {
  15. $connector = new WindowsPrintConnector("LPT1");
  16. // A FilePrintConnector will also work, but on non-Windows systems, writes
  17. // to an actual file called 'LPT1' rather than giving a useful error.
  18. // $connector = new FilePrintConnector("LPT1");
  19. /* Print a "Hello world" receipt" */
  20. $printer = new Printer($connector);
  21. $printer -> text("Hello World!\n");
  22. $printer -> cut();
  23. /* Close printer */
  24. $printer -> close();
  25. } catch (Exception $e) {
  26. echo "Couldn't print to this printer: " . $e -> getMessage() . "\n";
  27. }