Contoh Program Print Struk di PHP
<?php // Import the ESC/POS library require __DIR__ . '/vendor/autoload.php'; // Create a new printer object use Mike42\Escpos\PrintConnectors\FilePrintConnector; use Mike42\Escpos\Printer; $connector = new FilePrintConnector("/dev/usb/lp0"); $printer = new Printer($connector); // Print the receipt header $printer->text("RECEIPT"); $printer->text("--------------------------------------------------------------------------------"); // Print the customer information $printer->text("Customer Name: John Doe"); $printer->text("Customer Address: 123 Main Street, Anytown, CA 12345"); // Print the order information $printer->text("Order Number: 123456"); $printer->text("Order Date: 2023-05-24"); // Print the items in the order $printer->text("Item 1: \$10.00"); $printer->text("Item 2: \$20.00"); $printer->text("Item 3: \$30.00"); // Print the total amount $printer->text("Subtotal: \$60.00"); $printer->text("Tax: \$12.00"); $printer->text("Total: \$72.00"); // Print the receipt footer $printer->text("--------------------------------------------------------------------------------"); $printer->text("Thank you for your purchase!"); $printer->text("Please come again!"); // Cut the receipt $printer->cut(); // Close the printer $printer->close(); ?>
Kode ini akan mencetak struk dengan informasi berikut:
- Header struk
- Informasi pelanggan
- Informasi pesanan
- Item dalam pesanan
- Jumlah total
- Footer struk
Anda dapat menyesuaikan kode untuk mencetak informasi apa pun yang Anda inginkan di struk Anda. Misalnya, Anda dapat menambahkan logo, barcode, atau kode QR. Anda juga dapat mengubah jenis huruf, ukuran, dan warna teks.
Leave a Reply