public void imprimirFactura() {

    PrinterMatrix printer = new PrinterMatrix();

    // Extenso e = new Extenso();

    //   e.setNumber(101.85);

    // Definir el tamanho del papel para la impresion  aca 25 lineas y 80 columnas
    printer.setOutSize(60, 80);
    // Imprimir * de la 2da linea a 25 en la columna 1;
    // printer.printCharAtLin(2, 25, 1, "*");
    // Imprimir * 1ra linea de la columa de 1 a 80
    printer.printCharAtCol(1, 1, 80, "=");
    // Imprimir Encabezado nombre del La EMpresa
    printer.printTextWrap(1, 2, 30, 80, "FACTURA DE VENTA");
    // printer.printTextWrap(linI, linE, colI, colE, null);
    printer.printTextWrap(2, 3, 1, 22, "Num. Boleta : " + "0001");
    printer.printTextWrap(2, 3, 25, 55, "Fecha de Emision: " + "15-02/2015");
    printer.printTextWrap(2, 3, 60, 80, "Hora: 12:22:51");
    printer.printTextWrap(3, 3, 1, 80, "Vendedor.  : " + "VENNDD" + " - " + "DANIEL CAMACHO");
    printer.printTextWrap(4, 4, 1, 80, "CLIENTE: " + "jUAN");
    printer.printTextWrap(5, 5, 1, 80, "RUC/CI.: " + "12345687");
    printer.printTextWrap(6, 6, 1, 80, "DIRECCION: " + "");
    printer.printCharAtCol(7, 1, 80, "=");
    printer.printTextWrap(
        7,
        8,
        1,
        80,
        "Codigo          Descripcion                Cant.      P  P.Unit.      P.Total");
    printer.printCharAtCol(9, 1, 80, "-");
    //       int filas = tblVentas.getRowCount();

    //        for (int i = 0; i < filas; i++) { printer.printTextWrap(9 + i, 10, 1, 80,
    // tblVentas.getValueAt(i,0).toString()+"|"+tblVentas.getValueAt(i,1).toString()+"|
    // "+tblVentas.getValueAt(i,2).toString()+"| "+tblVentas.getValueAt(i,3).toString()+"|"+
    // tblVentas.getValueAt(i,4).toString()); } if(filas > 15){
    //        printer.printCharAtCol(filas + 1, 1, 80, "=");
    //        printer.printTextWrap(filas + 1, filas + 2, 1, 80, "TOTAL A PAGAR " +
    // txtVentaTotal.getText());
    //        printer.printCharAtCol(filas + 2, 1, 80, "=");
    //        printer.printTextWrap(filas + 2, filas + 3, 1, 80, "Esta boleta no tiene valor fiscal,
    // solo para uso interno.: + Descripciones........");
    //        }else{
    //        printer.printCharAtCol(25, 1, 80, "=");
    //        printer.printTextWrap(26, 26, 1, 80, "TOTAL A PAGAR " + txtVentaTotal.getText());
    //        printer.printCharAtCol(27, 1, 80, "=");
    //        printer.printTextWrap(27, 28, 1, 80, "Esta boleta no tiene valor fiscal, solo para uso
    // interno.: + Descripciones........");
    //
    //        }
    printer.toFile("impresion.txt");

    FileInputStream inputStream = null;
    try {
      inputStream = new FileInputStream("impresion.txt");
    } catch (FileNotFoundException ex) {
      ex.printStackTrace();
    }
    if (inputStream == null) {
      return;
    }

    DocFlavor docFormat = DocFlavor.INPUT_STREAM.AUTOSENSE;
    Doc document = new SimpleDoc(inputStream, docFormat, null);

    PrintRequestAttributeSet attributeSet = new HashPrintRequestAttributeSet();

    PrintService defaultPrintService = PrintServiceLookup.lookupDefaultPrintService();

    if (defaultPrintService != null) {
      DocPrintJob printJob = defaultPrintService.createPrintJob();
      try {
        printJob.print(document, attributeSet);

      } catch (Exception ex) {
        ex.printStackTrace();
      }
    } else {
      System.err.println("No existen impresoras instaladas");
    }

    // inputStream.close();

  }
Exemple #2
0
  @Override
  public void print(PrintService prserv, String sFilename, PrintRequestAttributeSet aset)
      throws PrintException, IOException {

    InputStream fis = null;
    try {
      DocPrintJob pj = prserv.createPrintJob();
      fis = new BufferedInputStream(new FileInputStream(sFilename));
      pj.print(
          new SimpleDoc(fis, DocFlavor.INPUT_STREAM.AUTOSENSE, null),
          (PrintRequestAttributeSet) aset);
    } catch (Exception e) {
      throw new PrintException(e.getMessage());
    } finally {
      if (fis != null) {
        fis.close();
      }
    }
  }
  public void print(String printer, byte[] bytes, String type) throws ReportException {
    try {

      PrintService printService;
      DocPrintJob job;
      DocFlavor fl;
      Doc doc;

      DocAttributeSet das = new HashDocAttributeSet();
      Object printObject;
      if (type == null || type.length() == 0) {
        fl = DocFlavor.BYTE_ARRAY.AUTOSENSE;
        printObject = bytes;
      } else if (type.equals(DocumentTypes.APPLICATION_PDF.toString())) {
        fl = DocFlavor.BYTE_ARRAY.AUTOSENSE;
        printObject = bytes;
      } else if (type.equals(DocumentTypes.TEXT_XML.toString())) {
        fl = DocFlavor.BYTE_ARRAY.AUTOSENSE;
        printObject = bytes;
      } else {
        log.info("Unknown type: " + type);
        fl = DocFlavor.INPUT_STREAM.AUTOSENSE;
        printObject = new ByteArrayInputStream(bytes);
      }

      if (printer != null && printer.equals(NO_PRINTER)) {
        log.info("Won't print. Printer: " + printer);
        return;
      }
      if (printer == null || printer.length() == 0 || printer.equals(DEFAULT_PRINTER)) {

        printService = PrintServiceLookup.lookupDefaultPrintService();

      } else {
        try {
          printService = getNamedPrintService(fl, printer);
        } catch (Exception ex) {
          log.log(Level.INFO, ex.getMessage(), ex);
          throw new IllegalArgumentException("Printer cannot be selected");
        }
      }

      if (printService == null) {
        log.info("printer not found: " + printer);
        throw new ReportException(ReportExceptionKey.PRINT_FAILED, printer);
      }

      doc = new SimpleDoc(printObject, fl, das);
      job = printService.createPrintJob();
      PrintJobWatcher watcher = null;

      if (fl instanceof DocFlavor.INPUT_STREAM) {
        watcher = new PrintJobWatcher(job);
      }

      job.print(doc, null);

      if (watcher != null) {
        watcher.waitForDone();
        ((InputStream) printObject).close();
      }

    } catch (PrintException ex) {
      log.log(Level.INFO, ex.getMessage(), ex);
      throw new ReportException(ReportExceptionKey.PRINT_FAILED, printer);
    } catch (Throwable ex) {
      log.log(Level.INFO, ex.getMessage(), ex);
      throw new ReportException(ReportExceptionKey.PRINT_FAILED, printer);
    }
  }
  public static void startPrinting(
      IApplication application,
      Pageable pageable,
      PrinterJob a_printerJob,
      String a_preferredPrinterName,
      boolean showPrinterSelectDialog,
      boolean avoidDialogs) {
    RepaintManager currentManager =
        RepaintManager.currentManager(application.getPrintingRendererParent().getParent());
    boolean isDoubleBufferingEnabled = false;
    try {
      if (currentManager != null) {
        isDoubleBufferingEnabled = currentManager.isDoubleBufferingEnabled();
      }

      if (a_printerJob != null) {
        // for plugin printing
        a_printerJob.setPageable(pageable);
        a_printerJob.setJobName("Servoy Print"); // $NON-NLS-1$
        if (showPrinterSelectDialog) {
          if (!a_printerJob.printDialog()) {
            return;
          }
          SwingHelper.dispatchEvents(100); // hide dialog
        }
        if (currentManager != null) {
          currentManager.setDoubleBufferingEnabled(false);
        }
        a_printerJob.print();
      } else {
        // by default we use old system for mac, new is not always working
        boolean useSystemPrintDialog =
            Utils.getAsBoolean(
                application
                    .getSettings()
                    .getProperty(
                        "useSystemPrintDialog",
                        "" + Utils.isAppleMacOS())); // $NON-NLS-1$//$NON-NLS-2$
        DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PAGEABLE;
        PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
        if (capablePrintServices == null) {
          capablePrintServices = PrintServiceLookup.lookupPrintServices(flavor, pras);
        }

        PrintService service = null;
        if (capablePrintServices == null || capablePrintServices.length == 0) {
          if (avoidDialogs) {
            Debug.warn("Cannot find capable print services. Print aborted.");
            return;
          } else {
            JOptionPane.showConfirmDialog(
                ((ISmartClientApplication) application).getMainApplicationFrame(),
                application.getI18NMessage("servoy.print.msg.noPrintersFound"),
                application.getI18NMessage(
                    "servoy.print.printing.title"), //$NON-NLS-1$ //$NON-NLS-2$
                JOptionPane.OK_OPTION,
                JOptionPane.ERROR_MESSAGE);
            capablePrintServices = new PrintService[0];
            showPrinterSelectDialog = true; // must show select printer and if none found show this
            useSystemPrintDialog =
                true; // we leave to system to show no printers are found, important for apple mac
          }
        } else {
          service = capablePrintServices[0]; // default select
        }

        PrintService systemDefaultPrinter = PrintServiceLookup.lookupDefaultPrintService();
        if (systemDefaultPrinter != null) {
          // check if system default printer is in capable list
          for (PrintService ps : capablePrintServices) {
            if (ps.getName().equalsIgnoreCase(systemDefaultPrinter.getName())) {
              service = systemDefaultPrinter;
              break;
            }
          }
        }

        boolean didFindPrinter = true; // want custom preferred printer
        if (a_preferredPrinterName != null) {
          didFindPrinter = false;
          for (PrintService ps : capablePrintServices) {
            if (ps.getName().equalsIgnoreCase(a_preferredPrinterName)) {
              didFindPrinter = true;
              service = ps;
              break;
            }
          }
        }

        if (!didFindPrinter) {
          if (avoidDialogs) {
            Debug.warn(
                "Cannot find capable printer for preferred form printer name '"
                    + a_preferredPrinterName
                    + "'. Trying to use default/any capable printer.");
          } else {
            showPrinterSelectDialog = true; // did not found the prefered , do show
          }
        }

        if (!useSystemPrintDialog) {
          if (showPrinterSelectDialog) {
            JFrame frame = ((ISmartClientApplication) application).getMainApplicationFrame();
            GraphicsConfiguration gc = frame.getGraphicsConfiguration();
            Point loc = frame.getLocation();
            service =
                ServiceUI.printDialog(
                    gc, loc.x + 50, loc.y + 50, capablePrintServices, service, flavor, pras);
          }
          if (service != null) {
            if (currentManager != null) {
              currentManager.setDoubleBufferingEnabled(false);
            }
            DocPrintJob job = service.createPrintJob();
            DocAttributeSet das = new HashDocAttributeSet();
            Doc doc = new SimpleDoc(pageable, flavor, das);
            if (job != null) {
              job.print(doc, pras);
            } else {
              // for example if the print service cancels (e.g. print to pdf and then user cancel
              // when choosing save location)
              application.reportWarning(
                  application.getI18NMessage(
                      "servoy.print.error.cannotPrintDocument")); //$NON-NLS-1$
            }
          }
        } else {
          a_printerJob = PrinterJob.getPrinterJob();
          a_printerJob.setPageable(pageable);
          a_printerJob.setJobName("Servoy Print"); // $NON-NLS-1$
          if (service != null) {
            a_printerJob.setPrintService(service);
          }
          if (showPrinterSelectDialog) {
            if (!a_printerJob.printDialog()) {
              return;
            }
            SwingHelper.dispatchEvents(100); // hide dialog
          }
          if (currentManager != null) {
            currentManager.setDoubleBufferingEnabled(false);
          }
          a_printerJob.print();
        }
      }
    } catch (Exception ex) {
      application.reportError(
          application.getI18NMessage("servoy.print.error.cannotPrintDocument"), ex); // $NON-NLS-1$
    } finally {
      if (currentManager != null) {
        currentManager.setDoubleBufferingEnabled(isDoubleBufferingEnabled);
      }
    }
  }
  /*
   * Metodo que imprime directamente en una impresra byte
   */
  public void printExtra(CexAgenda turno) throws IOException {
    // FileInputStream inputStream = null;
    InputStream tex = null;
    SimpleDateFormat sf = new SimpleDateFormat("dd/MM/yyyy");
    String fecha = sf.format(turno.getCagFecha());
    SimpleDateFormat sfHora = new SimpleDateFormat("HH:mm");
    String hora = "";
    String te2;
    if (turno.getCagHora() != null) {
      hora = sfHora.format(turno.getCagHora());
    }
    String impresora = "SIN IMPRESORA";
    PrintService impresora11 = null;
    try {
      // inputStream = new FileInputStream("e:/archivo.txt");

      String cadena =
          "************************************* \n\n"
                      + "RESPONSABLE: "
                      + turno.getCagNombreUsuario()
                      + " \n"
                      + "FECHA: "
                      + fecha
                      + " \n"
                      + turno.getCagNombreInstitucion()
                      + "\n"
                      + turno
                          .getCexHorariosDia()
                          .getCexHorario()
                          .getCexEspecialidadMedico()
                          .getCexEspecialidad()
                          .getCesNombre()
                      + "\n"
                      + "NÚMERO CARPETA: "
                      + turno.getHosReferencia()
                  != null
              ? turno.getHosReferencia().getCexHistoriaInstitucion().getCicNumeroCarpeta()
              : turno.getCexHistoriaInstitucion().getCicNumeroCarpeta()
                          + "\n"
                          + "CÉDULA: "
                          + turno.getHosReferencia()
                      != null
                  ? turno
                      .getHosReferencia()
                      .getCexHistoriaInstitucion()
                      .getCexHistoriaClinica()
                      .getChcCedula()
                  : turno.getCexHistoriaInstitucion().getCexHistoriaClinica().getChcCedula()
                              + "\n"
                              + "TURNO: "
                              + turno.getCagSecuencia()
                              + "\t HORA: "
                              + hora
                              + " \n"
                              + "MEDICO: "
                              + turno
                                  .getCexHorariosDia()
                                  .getCexHorario()
                                  .getCexEspecialidadMedico()
                                  .getAdmMedico()
                                  .getAmeNombreFull()
                              + "\n"
                              + "PACIENTE: "
                              + turno.getHosReferencia()
                          != null
                      ? turno
                          .getHosReferencia()
                          .getCexHistoriaInstitucion()
                          .getCexHistoriaClinica()
                          .getChcNombreFull()
                      : turno.getCexHistoriaInstitucion().getCexHistoriaClinica().getChcNombreFull()
                          + "\n"
                          + "*******   TURNO        EXTRA    ********\n"
                          + "\n"
                          + "\n"
                          + "SE RECOMIENDA ESTAR 30 MIN ANTES\n"
                          + " DE LA HORA ESPECIFICADA\n"
                          + "\n";
      te2 = converteCaracter(cadena);
      tex = new ByteArrayInputStream(te2.getBytes("UTF-8"));

    } catch (UnsupportedEncodingException e) {
      log.error("printExtra() {} ", e.getMessage());
    }
    if (tex == null) {
      return;
    }

    DocFlavor docFormat = DocFlavor.INPUT_STREAM.AUTOSENSE;
    Doc document = new SimpleDoc(tex, docFormat, null);

    PrintRequestAttributeSet attributeSet = new HashPrintRequestAttributeSet();

    for (AdmDatosGlobales datoGlobal : listaImpresorasturnos) {
      if (user.getIp().equals(datoGlobal.getClave())) {
        impresora = datoGlobal.getValor();
        break;
      }
    }
    // PrintService impresora11 = PrintServiceLookup.lookupDefaultPrintService();
    PrintService[] printService = PrintServiceLookup.lookupPrintServices(null, null);
    for (PrintService printService1 : printService) {
      if (printService1.getName().equals(impresora)) {
        impresora11 = printService1;
      }
    }

    if (impresora11 != null) {
      DocPrintJob printJob = impresora11.createPrintJob();
      try {
        printJob.print(document, attributeSet);
      } catch (PrintException e) {
        log.error("printExtra() {} ", e.getMessage());
      }
    } else {
      log.error("No existen impresoras instaladas");
    }

    tex.close();
  }
  public void print_labels(PrintService psZebra, int row, boolean glued) {
    try {

      IDColumn column = (IDColumn) xProductTable.getValueAt(row, 0);
      KeyNamePair knp_product = (KeyNamePair) xProductTable.getValueAt(row, 3);
      KeyNamePair knp_att = (KeyNamePair) xProductTable.getValueAt(row, 11);

      MVMRDiscountAppliDetail detail =
          new MVMRDiscountAppliDetail(Env.getCtx(), column.getRecord_ID(), null);

      int cantidadEtiquetas = ((Number) xProductTable.getValueAt(row, 6)).intValue();

      MProduct producto = new MProduct(Env.getCtx(), knp_product.getKey(), null);
      String name = producto.getName();
      /*
       * Caracteristica larga
       * */
      X_XX_VMR_LongCharacteristic caracLarga =
          new X_XX_VMR_LongCharacteristic(
              Env.getCtx(), producto.getXX_VMR_LongCharacteristic_ID(), null);
      X_M_AttributeSet attrSet =
          new X_M_AttributeSet(Env.getCtx(), producto.getM_AttributeSet_ID(), null);

      DecimalFormat formato = new DecimalFormat(".##");

      // String attr = "AMARILLO T=G                  ";
      // "CHEMISE CABALLERO             "

      X_XX_VMR_Department dep =
          new X_XX_VMR_Department(Env.getCtx(), producto.getXX_VMR_Department_ID(), null);
      String departmentCode = dep.getValue();

      X_XX_VMR_Line lin = new X_XX_VMR_Line(Env.getCtx(), producto.getXX_VMR_Line_ID(), null);
      String lineCode = lin.getValue();

      X_XX_VMR_Section sec =
          new X_XX_VMR_Section(Env.getCtx(), producto.getXX_VMR_Section_ID(), null);
      String seccionCode = sec.getValue();
      String precio = formato.format(detail.getXX_PriceBeforeDiscount());

      MVMRDiscountRequest headerDiscount =
          new MVMRDiscountRequest(Env.getCtx(), detail.getXX_VMR_DiscountRequest_ID(), null);
      MWarehouse tienda = new MWarehouse(Env.getCtx(), headerDiscount.getM_Warehouse_ID(), null);

      X_XX_VMR_PriceConsecutive consecutivoViejo =
          new X_XX_VMR_PriceConsecutive(Env.getCtx(), detail.getXX_VMR_PriceConsecutive_ID(), null);
      // Debo buscar semana, mes y año de la fecha de creacion del consecutivo

      Date date = (Date) consecutivoViejo.getCreated();
      Calendar cal = new GregorianCalendar();
      cal.setTime(date);
      int mes = cal.get(Calendar.MONTH) + 1;
      int año = cal.get(Calendar.YEAR);
      int semana = cal.get(Calendar.WEEK_OF_YEAR);

      BigDecimal impuesto = new BigDecimal(0);

      if (producto.getC_TaxCategory_ID() != 0) {

        String sql_rate =
            " SELECT (RATE) FROM C_TAX "
                + " WHERE C_TaxCategory_ID= "
                + producto.getC_TaxCategory_ID()
                + " AND ValidFrom <= to_date('"
                + date.toString().substring(0, 10)
                + "','yyyy-mm-dd')"
                + " and rownum = 1 "
                + " order by ValidFrom desc ";
        try {
          PreparedStatement prst_tax = DB.prepareStatement(sql_rate, null);
          ResultSet rs_tax = prst_tax.executeQuery();
          if (rs_tax.next()) {

            impuesto = rs_tax.getBigDecimal(1).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP);
          }
          rs_tax.close();
          prst_tax.close();
        } catch (Exception e) {
          System.out.println("error al calcular el impuesto");
        }
      }

      String product_plus_correlative =
          "" + producto.getValue() + consecutivoTostring(consecutivoViejo.getXX_PriceConsecutive());

      String s = "";
      DocPrintJob job = psZebra.createPrintJob();

      if (impuesto.compareTo(new BigDecimal(0)) > 0) {
        precio =
            formato.format(
                (detail
                        .getXX_PriceBeforeDiscount()
                        .add((detail.getXX_PriceBeforeDiscount()).multiply(impuesto)))
                    .setScale(2, BigDecimal.ROUND_HALF_UP));
        s =
            "^XA^PRD^XZ\n"
                + "^XA^JMA^\n"
                + "^LH07,02^FS\n"
                + "^FO10,03^BE,25,N^BY3, 0.5,45^FD"
                + product_plus_correlative
                + "^FS\n"
                + "^FO10,62^AA,15,12^FD"
                + departmentCode
                + "-"
                + lineCode
                + "-"
                + seccionCode
                + "-"
                + product_plus_correlative
                + "       ^FS\n"
                + "^FO10,82^AA,20,10^FD"
                + name
                + "^FS\n";
        if (!attrSet.getName().isEmpty()
            && attrSet.get_ID() != Env.getCtx().getContextAsInt("#XX_L_P_ATTRIBUTESETST_ID")) {
          s =
              s
                  + "^FO10,97^AA,20,10^FD"
                  + (attrSet.getName().length() > 30
                      ? attrSet.getName().substring(0, 29)
                      : attrSet.getName())
                  + "^FS\n";
        } else if (caracLarga != null
            && caracLarga.getName() != null
            && !caracLarga.getName().isEmpty()) {
          s =
              s
                  + "^FO10,97^AA,20,10^FD"
                  + (caracLarga.getName().length() > 30
                      ? caracLarga.getName().substring(0, 29)
                      : caracLarga.getName())
                  + "^FS\n";
        }
        s =
            s
                + "^FO10,116^AA,14,10^FDPRECIO BS^FS\n"
                + "^FO10,170^AB,11,07^FDRIF J-00046517-7   Incluye IVA "
                + impuesto.multiply(new BigDecimal(100))
                + "%^FS\n"
                + "^FO10,153^AB,11,07^CI10^FD"
                + semana
                + " "
                + mes
                + " "
                + año
                + "^FS\n"
                + "^FO10,138^AA,11,09^FDBsF.^FS\n"
                + "^FO35,136^AB,11,07^CI10^FD         "
                + precio
                + "^FS\n"
                + "^PQ"
                + cantidadEtiquetas
                + "^FS\n"
                + "^XZ\n"
                +
                // Control label
                "^XA^PRD^XZ\n"
                + "^XA^JMA^\n"
                + "^LH00,15^FS\n"
                + "^FO2,5^AD,38,10^FD*CONTROL*     "
                + semana
                + " "
                + mes
                + ""
                + año
                + "^FS\n"
                + "^FO05,45^A0,30,07^FD                  TDA:  "
                + tienda.getValue()
                + "^FS\n"
                + "^FO28,48^A0,15,14^FDCANT:     "
                + cantidadEtiquetas
                + "      PRECIO      "
                + precio
                + "^FS\n"
                + "^FO05,95^A0,18,10^FD"
                + departmentCode
                + "-"
                + lineCode
                + "-"
                + seccionCode
                + "- "
                + product_plus_correlative
                + "^FS\n"
                + "^FO05,120^A0,18,10^FD"
                + name
                + "^FS\n"
                + "^FO05,140^A0,18,10^FD                                                  ^FS\n"
                + "^PQ1^FS\n"
                + "^XZ";
      } else {
        s =
            "^XA^PRD^XZ\n"
                + "^XA^JMA^\n"
                + "^LH07,02^FS\n"
                + "^FO10,03^BE,25,N^BY3, 0.5,45^FD"
                + product_plus_correlative
                + "^FS\n"
                + "^FO10,62^AA,15,12^FD"
                + departmentCode
                + "-"
                + lineCode
                + "-"
                + seccionCode
                + "-"
                + product_plus_correlative
                + "       ^FS\n"
                + "^FO10,82^AA,20,10^FD"
                + name
                + "^FS\n"
                + "^FO10,97^AA,20,10^FD                                                  ^FS\n"
                + "^FO10,116^AA,14,10^FDPRECIO BS^FS\n"
                + "^FO10,170^AB,11,07^FDRIF J-00046517-7   Exento de Iva%^FS\n"
                + "^FO10,153^AB,11,07^CI10^FD"
                + semana
                + " "
                + mes
                + " "
                + año
                + "^FS\n"
                + "^FO10,138^AA,11,09^FDBsF.^FS\n"
                + "^FO35,136^AB,11,07^CI10^FD         "
                + precio
                + "^FS\n"
                + "^PQ"
                + cantidadEtiquetas
                + "^FS\n"
                + "^XZ\n"
                +
                // Control label
                "^XA^PRD^XZ\n"
                + "^XA^JMA^\n"
                + "^LH00,15^FS\n"
                + "^FO2,5^AD,38,10^FD*CONTROL*     "
                + semana
                + " "
                + mes
                + ""
                + año
                + "^FS\n"
                + "^FO05,45^A0,30,07^FD                  TDA:  "
                + tienda.getValue()
                + "^FS\n"
                + "^FO28,48^A0,15,14^FDCANT:     "
                + cantidadEtiquetas
                + "      PRECIO      "
                + precio
                + "^FS\n"
                + "^FO05,95^A0,18,10^FD"
                + departmentCode
                + "-"
                + lineCode
                + "-"
                + seccionCode
                + "- "
                + product_plus_correlative
                + "^FS\n"
                + "^FO05,120^A0,18,10^FD"
                + name
                + "^FS\n"
                + "^FO05,140^A0,18,10^FD                                                  ^FS\n"
                + "^PQ1^FS\n"
                + "^XZ";
      }

      byte[] by = s.getBytes();
      DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
      Doc doc = new SimpleDoc(by, flavor, null);
      job.print(doc, null);

    } catch (Exception e) {
      e.printStackTrace();
    }
  }