windows-usb.php 1.1KB

1234567891011121314151617181920212223242526272829303132333435
  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. * Install the printer using USB printing support, and the "Generic / Text Only" driver,
  8. * then share it (you can use a firewall so that it can only be seen locally).
  9. *
  10. * Use a WindowsPrintConnector with the share name to print.
  11. *
  12. * Troubleshooting: Fire up a command prompt, and ensure that (if your printer is shared as
  13. * "Receipt Printer), the following commands work:
  14. *
  15. * echo "Hello World" > testfile
  16. * copy testfile "\\%COMPUTERNAME%\Receipt Printer"
  17. * del testfile
  18. */
  19. try {
  20. // Enter the share name for your USB printer here
  21. $connector = null;
  22. //$connector = new WindowsPrintConnector("Receipt Printer");
  23. /* Print a "Hello world" receipt" */
  24. $printer = new Printer($connector);
  25. $printer -> text("Hello World!\n");
  26. $printer -> cut();
  27. /* Close printer */
  28. $printer -> close();
  29. } catch (Exception $e) {
  30. echo "Couldn't print to this printer: " . $e -> getMessage() . "\n";
  31. }