Exemplo n.º 1
1
function print_prenote2($prenote)
{
    include '../db/config.php';
    //$printerList = printer_list(PRINTER_ENUM_LOCAL);
    if ($printerHandler = printer_open($prenote->printer->name)) {
        printer_set_option($printerHandler, PRINTER_MODE, "raw");
        printer_start_doc($printerHandler, "Prenote " . $prenote->folio);
        printer_start_page($printerHandler);
        $fontHeight = 30;
        $fontWidth = 15;
        $fontWeight = 200;
        $firstLine = 80;
        $lineNumber = 0;
        $image = $prenote->folio . '.bmp';
        $filename = $rootPath . "php\\db\\" . $image;
        $font = printer_create_font("Arial", $fontHeight, $fontWidth, $fontWeight, false, false, false, 0);
        printer_select_font($printerHandler, $font);
        printer_draw_bmp($printerHandler, $filename, 150, 1);
        printer_draw_text($printerHandler, $prenote->folio, 158, calculateNextLine($lineNumber++));
        printer_draw_text($printerHandler, $prenote->clientName, 1, calculateNextLine($lineNumber++));
        printer_draw_text($printerHandler, "-----------------------------------------------------------", 1, calculateNextLine($lineNumber++));
        $product = $prenote->product;
        $length = count($product);
        for ($i = 0; $i < $length; $i++) {
            printer_draw_text($printerHandler, utf8_decode($product[$i]->Description), 1, calculateNextLine($lineNumber++));
            printer_draw_text($printerHandler, $product[$i]->scanCode, 1, calculateNextLine($lineNumber));
            printer_draw_text($printerHandler, $product[$i]->unitName, 151, calculateNextLine($lineNumber));
            printer_draw_text($printerHandler, $product[$i]->Quantity, 351, calculateNextLine($lineNumber));
            $precio_cantidad = $product[$i]->Quantity * $product[$i]->Price;
            printer_draw_text($printerHandler, '$' . $precio_cantidad, 451, calculateNextLine($lineNumber++));
            printer_draw_text($printerHandler, $product[$i]->serialBatch, 1, calculateNextLine($lineNumber++));
        }
        printer_draw_text($printerHandler, "-----------------------------------------------------------", 1, calculateNextLine($lineNumber++));
        printer_draw_text($printerHandler, $prenote->narticles, 151, calculateNextLine($lineNumber));
        printer_draw_text($printerHandler, '$' . $prenote->total, 351, calculateNextLine($lineNumber++));
        printer_draw_text($printerHandler, $prenote->id_employee, 1, calculateNextLine($lineNumber));
        printer_draw_text($printerHandler, $prenote->employeeName, 101, calculateNextLine($lineNumber++));
        printer_draw_text($printerHandler, $prenote->store_id, 1, calculateNextLine($lineNumber));
        printer_draw_text($printerHandler, $prenote->store_name, 101, calculateNextLine($lineNumber++));
        printer_draw_text($printerHandler, $prenote->cotizationNumber, 1, calculateNextLine($lineNumber++));
        printer_draw_text($printerHandler, $prenote->date, 1, calculateNextLine($lineNumber));
        printer_end_page($printerHandler);
        printer_end_doc($printerHandler);
        printer_close($printerHandler);
        return true;
    } else {
        return false;
    }
}
Exemplo n.º 2
-1
 public function enviar_a_impresora($data = array())
 {
     // Envia documento a impresora via printer.dll (Windows)
     $this->impresora = isset($data['impresora']) ? $data['impresora'] : $this->impresora;
     $this->logo = isset($data['logo']) ? $data['logo'] : '';
     $this->contenido = isset($data['contenido']) ? $data['contenido'] : '';
     $this->formato = isset($data['formato']) ? $data['formato'] : '';
     $this->codebar = isset($data['codebar']) ? $data['codebar'] : '';
     $this->codeqr = isset($data['codeqr']) ? $data['codeqr'] : '';
     if ($this->formato) {
         // Lee archivo y extrae contenido para enviarlo a la impresora
         $this->fh = fopen($this->contenido, "r");
         while (!feof($this->fh)) {
             $this->texto[] = fgets($this->fh);
         }
         fclose($this->fh);
         $isfile = true;
     } else {
         $this->texto = $this->contenido;
     }
     if ($this->impresora && $this->texto) {
         if ($this->ph = printer_open($this->impresora)) {
             #Crea manejador de impresora
             #Contrucción de documento en impresora
             // Inicio de doc y page
             printer_start_doc($this->ph);
             printer_start_page($this->ph);
             // Set print mode to RAW and send PDF to printer
             printer_set_option($this->ph, PRINTER_MODE, "RAW");
             $salto_linea = 0;
             if ($this->formato) {
                 if (file_exists($this->logo)) {
                     // Imagen BMP - Logo
                     printer_draw_bmp($this->ph, $this->logo, $this->var['ticket']['ticket_logo_x'], $this->var['ticket']['ticket_logo_y'], $this->var['ticket']['ticket_logo_w'], $this->var['ticket']['ticket_logo_h']);
                     $salto_linea = $this->var['ticket']['ticket_logo_salto'];
                 }
                 // Crear formato de texto
                 $estilo = printer_create_font($this->var['ticket']['ticket_formato_font'], $this->var['ticket']['ticket_formato_h'], $this->var['ticket']['ticket_formato_w'], $this->var['ticket']['ticket_formato_font_w'], $this->var['ticket']['ticket_formato_font_italic'], $this->var['ticket']['ticket_formato_font_underline'], $this->var['ticket']['ticket_formato_font_strikeout'], $this->var['ticket']['ticket_formato_font_orientation']);
                 printer_select_font($this->ph, $estilo);
                 // Contenido
                 if ($isfile) {
                     $txtArray = $this->texto;
                     for ($i = 0; $i < count($txtArray); $i++) {
                         printer_draw_text($this->ph, $txtArray[$i], $this->var['ticket']['ticket_contenido_x'], $salto_linea);
                         #Izq; Alto
                         $salto_linea += $this->var['ticket']['ticket_contenido_salto'];
                     }
                 } else {
                     printer_draw_text($this->ph, $this->texto, $this->var['ticket']['ticket_contenido_x'], $salto_linea);
                 }
                 // Eliminar formato de texto
                 printer_delete_font($estilo);
                 // Codigo de Barras
                 if ($this->codebar && file_exists($this->codebar)) {
                     printer_draw_bmp($this->ph, $this->codebar, $this->var['ticket']['ticket_barscode_x'], $salto_linea, $this->var['ticket']['ticket_barscode_w'], $this->var['ticket']['ticket_barscode_h']);
                     $salto_linea += $this->var['ticket']['ticket_barscode_salto'];
                 }
                 // Codigo QR
                 if ($this->codeqr && file_exists($this->codeqr)) {
                     printer_draw_bmp($this->ph, $this->codeqr, $this->var['ticket']['ticket_qrcode_x'], $salto_linea, $this->var['ticket']['ticket_qrcode_w'], $this->var['ticket']['ticket_qrcode_h']);
                     $salto_linea += $this->var['ticket']['ticket_qrcode_salto'];
                 }
                 // Footer
                 if ($this->footer) {
                     $estilo = printer_create_font($this->var['ticket']['ticket_formato_footer_font'], $this->var['ticket']['ticket_formato_footer_h'], $this->var['ticket']['ticket_formato_footer_w'], $this->var['ticket']['ticket_formato_footer_font_w'], $this->var['ticket']['ticket_formato_footer_font_italic'], $this->var['ticket']['ticket_formato_footer_font_underline'], $this->var['ticket']['ticket_formato_footer_font_strikeout'], $this->var['ticket']['ticket_formato_footer_font_orientation']);
                     printer_select_font($this->ph, $estilo);
                     printer_draw_text($this->ph, date('Y-m-d H:i:s'), $this->var['ticket']['ticket_footer_x'], $salto_linea);
                     printer_delete_font($estilo);
                 }
             } else {
                 printer_write($this->ph, $this->texto);
                 #texto sin formato
             }
             // Fin de documento y página
             printer_end_page($this->ph);
             printer_end_doc($this->ph);
             // Cierra archivo y envía a imprimir
             printer_close($this->ph);
             $this->respuesta = true;
         }
     }
     return $this->respuesta;
 }