SHOW:
|
|
- or go back to the newest paste.
| 1 | <?php | |
| 2 | ||
| 3 | class Controller extends CI_Controller | |
| 4 | {
| |
| 5 | ||
| 6 | function __construct() | |
| 7 | {
| |
| 8 | parent::__construct(); | |
| 9 | } | |
| 10 | ||
| 11 | function index() | |
| 12 | {
| |
| 13 | $this->load->view('view');
| |
| 14 | } | |
| 15 | ||
| 16 | function generateQr() | |
| 17 | {
| |
| 18 | $string = $this->input->post('string');
| |
| 19 | ||
| 20 | $this->load->library('ciqrcode'); // pemanggilan library
| |
| 21 | ||
| 22 | $config['cacheable'] = true; // boolean, defaultnya true | |
| 23 | $config['cachedir'] = './assets/'; //string, the default is application/cache/ | |
| 24 | $config['errorlog'] = './assets/'; //string, the default is application/logs/ | |
| 25 | $config['imagedir'] = './assets/images/'; // direktori penyimpanan qr code | |
| 26 | $config['quality'] = true; // boolean, defaultnya true | |
| 27 | $config['size'] = 1024; // integer, defaultnya 1024; | |
| 28 | $config['black'] = array(224, 255, 255); // array, defaultnya array(255, 255, 255) | |
| 29 | $config['white'] = array(70, 130, 180); // array, defaultnya array(0, 0, 0); | |
| 30 | $this->ciqrcode->initialize($config); | |
| 31 | ||
| 32 | $image_name = $string.'.png'; // pembuatan nama qr code | |
| 33 | ||
| 34 | $params['data'] = $string; | |
| 35 | $params['level'] = 'L'; | |
| 36 | $params['size'] = 10; | |
| 37 | $params['savename'] = FCPATH.$config['imagedir'].$image_name; | |
| 38 | $qr = $this->ciqrcode->generate($params); | |
| 39 | sleep(3); | |
| 40 | - | $this->print_receipt($image_name); |
| 40 | + | if(is_file(FCPATH.$config['imagedir'].$image_name)) |
| 41 | {
| |
| 42 | $this->print_receipt($image_name); | |
| 43 | } | |
| 44 | else | |
| 45 | {
| |
| 46 | die('image:'.FCPATH.$config['imagedir'].$image_name."| not found");
| |
| 47 | ||
| 48 | - | require(FCPATH.'/vendor/autoload.php'); |
| 48 | + | } |
| 49 | redirect('');
| |
| 50 | } | |
| 51 | ||
| 52 | function print_receipt($string) | |
| 53 | {
| |
| 54 | // load library | |
| 55 | require_once(FCPATH.'/vendor/autoload.php'); | |
| 56 | ||
| 57 | // membuat connector printer ke shared printer bernama "printer_a" (yang telah disetting sebelumnya) | |
| 58 | /** | |
| 59 | * cara setting printer: | |
| 60 | * 1. masuk ke control panel -> devices and printers | |
| 61 | * 2. klik kanan printer, pilih "Set as Default Printer" | |
| 62 | * 3. klik kanan printer, pilih "Printer properties" | |
| 63 | * 4. pilih tab "Sharing" | |
| 64 | * 5. centang checkbox "Share this printer" | |
| 65 | * 6. isi nama di kolom "Share name". Share name ini akan digunakan sebagai parameter connector | |
| 66 | * 7. klik apply/OK | |
| 67 | * */ | |
| 68 | $connector = new Mike42\Escpos\PrintConnectors\WindowsPrintConnector("printer_a");
| |
| 69 | ||
| 70 | // membuat objek $printer agar dapat di lakukan fungsinya | |
| 71 | - | $tux = Mike42\Escpos\EscposImage::load(base_url().'assets/images/'.$string, false); |
| 71 | + | |
| 72 | ||
| 73 | $printer->initialize(); | |
| 74 | $printer->text("QR CODE");
| |
| 75 | $printer->text("\n");
| |
| 76 | ||
| 77 | $printer->initialize(); | |
| 78 | $tux = Mike42\Escpos\EscposImage::load(FCPATH.$config['imagedir'].$image_name); | |
| 79 | //base_url().'assets/images/'.$string, false); | |
| 80 | $printer->bitImageColumnFormat($tux, Mike42\Escpos\Printer::IMG_DOUBLE_WIDTH || Mike42\Escpos\Printer::IMG_DOUBLE_HEIGHT); | |
| 81 | $printer->text("\n");
| |
| 82 | ||
| 83 | $printer->feed(2); // mencetak 2 baris kosong, agar kertas terangkat ke atas | |
| 84 | $printer->cut(); | |
| 85 | ||
| 86 | $printer->close(); | |
| 87 | } | |
| 88 | } |