/**
   * Takes a printer name and find the associated PrintService. If no match can be made it randomly
   * picks the first printer listed from the call to lookupPrintServices.
   *
   * @param printerName
   * @return PrintService referenced by the printerName
   */
  public PrintService getPrinterInternal(final String printerName, final String lastPrinterName) {
    // The parameter value was not provided, and we are allowed to create
    // user interface forms

    PrintService[] services = PrinterJob.lookupPrintServices();
    for (PrintService element : services) {
      if (element.getName().equals(printerName)) {
        return element;
      }
    }
    if (feedbackAllowed()) {
      // If it's not valid then lets find one and end this current run.
      ArrayList values = new ArrayList();
      for (PrintService element : services) {
        String value = element.getName();
        values.add(value);
      }
      createFeedbackParameter(
          StandardSettings.PRINTER_NAME,
          Messages.getInstance().getString("PrintComponent.USER_PRINTER_NAME"),
          "",
          lastPrinterName,
          values,
          null,
          "select"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
      promptNeeded();
      return null;
    }
    return services[0];
  }
  private synchronized void refreshServices() {
    printers = peer.getAllPrinterNames();
    if (printers == null) {
      // In Windows it is safe to assume no default if printers == null so we
      // don't get the default.
      printServices = new PrintService[0];
      return;
    }

    PrintService[] newServices = new PrintService[printers.length];
    PrintService defService = getDefaultPrintService();
    for (int p = 0; p < printers.length; p++) {
      if (defService != null && printers[p].equals(defService.getName())) {
        newServices[p] = defService;
      } else {
        if (printServices == null) {
          newServices[p] = new Win32PrintService(printers[p], peer);
        } else {
          int j;
          for (j = 0; j < printServices.length; j++) {
            if ((printServices[j] != null) && (printers[p].equals(printServices[j].getName()))) {
              newServices[p] = printServices[j];
              printServices[j] = null;
              break;
            }
          }
          if (j == printServices.length) {
            newServices[p] = new Win32PrintService(printers[p], peer);
          }
        }
      }
    }

    printServices = newServices;
  }
Example #3
0
  private void printDoc() {
    try {
      PrintService printService = null;
      PrintService[] printServices = PrintServiceLookup.lookupPrintServices(null, null);
      for (PrintService ps : printServices) {
        if (ps.getName().equals(printerName)) {
          printService = ps;
          break;
        }
      }

      if (printService == null) {
        return;
      }

      PrinterJob job = PrinterJob.getPrinterJob();
      job.setPrintService(printService);
      CustomPaper customPaper = new CustomPaper(pageWidth, pageHeight);
      customPaper.setPrintArea(printAreaTop, printAreaLeft, printAreaWidth, printAreaHeight);

      PageFormat pf = job.defaultPage();
      pf.setPaper(customPaper);
      job.defaultPage(pf);
      job.setPrintable(this, pf);
      job.print();

    } catch (PrinterException | HeadlessException e) {
      System.err.println(e);
      Logger.getGlobal().log(Level.SEVERE, null, e);
    }
  }
Example #4
0
  public static void exporterPapier(JasperPrint jPrint, Integer nbCopies) {

    // choix de l'imprimante par défaut
    PrintService service = PrintServiceLookup.lookupDefaultPrintService();

    // paramètres d'impression
    PrintRequestAttributeSet printRequestAttributeSetImpression =
        new HashPrintRequestAttributeSet();
    printRequestAttributeSetImpression.add(MediaSizeName.ISO_A4);
    printRequestAttributeSetImpression.add(new Copies(nbCopies));

    // paramètres de l'imprimante
    PrintServiceAttributeSet printServiceAttributeSetImpression =
        new HashPrintServiceAttributeSet();
    printServiceAttributeSetImpression.add(new PrinterName(service.getName(), null));

    // création de l'interface d'impression
    JRPrintServiceExporter imprimanteFacture = new JRPrintServiceExporter();

    // initialisation de l'interface d'impression
    imprimanteFacture.setParameter(JRExporterParameter.JASPER_PRINT, jPrint);
    imprimanteFacture.setParameter(
        JRPrintServiceExporterParameter.PRINT_REQUEST_ATTRIBUTE_SET,
        printRequestAttributeSetImpression);
    imprimanteFacture.setParameter(
        JRPrintServiceExporterParameter.PRINT_SERVICE_ATTRIBUTE_SET,
        printServiceAttributeSetImpression);

    try {
      imprimanteFacture.exportReport();
    } catch (Exception e) {
      throw new RuntimeException("Impossible de générer la Facture", e);
      //  COMMANDE ENREGISTREE MAIS NON IMPRIMEE
    }
  }
Example #5
0
 ServiceNotifier(PrintService service) {
   super(service.getName() + " notifier");
   this.service = service;
   listeners = new Vector();
   try {
     setPriority(Thread.NORM_PRIORITY - 1);
     setDaemon(true);
     start();
   } catch (SecurityException e) {
   }
 }
  // for retreiving all the printer name
  public String[] getAllPrinterName() {

    PrintService[] MetaPrinter = PrintServiceLookup.lookupPrintServices(null, null);
    ArrayList<String> PrinterNameStack = new ArrayList<>();
    // PrintService DefaultPrinter = PrintServiceLookup.lookupDefaultPrintService();
    for (PrintService printer : MetaPrinter) {
      String printname = printer.getName();
      PrinterNameStack.add(printname);
    }
    return PrinterNameStack.toArray(new String[PrinterNameStack.size()]);
  }
  /**
   * Takes a printer name and find the associated PrintService. If no match can be made it randomly
   * picks the first printer listed from the call to lookupPrintServices.
   *
   * @param printerName
   * @return PrintService referenced by the printerName
   */
  public static PrintService getPrinter(final String printerName) {
    // The parameter value was not provided, and we are allowed to create
    // user interface forms

    PrintService[] services = PrinterJob.lookupPrintServices();
    for (PrintService element : services) {
      if (element.getName().equals(printerName)) {
        return element;
      }
    }
    return services[0];
  }
Example #8
0
 @Cached
 /* package */ PrintService getSystemPrintService(final String printerName) {
   final PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);
   if (services == null || services.length == 0) {
     return null;
   }
   for (final PrintService service : services) {
     if (service.getName().equals(printerName)) {
       return service;
     }
   }
   return null;
 }
  @Override
  public void startConsumeTask(Map<String, Object> printServices) {
    // 获取所有打印服务
    PrintService[] tempPrintServices = new PrintUtils().getAllPrintService();
    List<PrintService> printServiceList = new ArrayList<PrintService>();

    // 获取用户选择的打印服务对象
    for (PrintService printService : tempPrintServices) {
      if (printServices.containsKey(printService.getName())) {
        printServiceList.add(printService);
      }
    }

    // 处理任务
    scheduler.startConsumeTask(printServiceList);
  }
Example #10
0
  private synchronized void refreshServices() {
    printers = getAllPrinterNames();
    if (printers == null) {
      // In Windows it is safe to assume no default if printers == null so we
      // don't get the default.
      printServices = null;
      return;
    }

    PrintService[] newServices = new PrintService[printers.length];
    PrintService defService = getDefaultPrintService();
    for (int p = 0; p < printers.length; p++) {
      if (defService != null && printers[p].equals(defService.getName())) {
        newServices[p] = defService;
      } else {
        if (printServices == null) {
          newServices[p] = new Win32PrintService(printers[p]);
        } else {
          int j;
          for (j = 0; j < printServices.length; j++) {
            if ((printServices[j] != null) && (printers[p].equals(printServices[j].getName()))) {
              newServices[p] = printServices[j];
              printServices[j] = null;
              break;
            }
          }
          if (j == printServices.length) {
            newServices[p] = new Win32PrintService(printers[p]);
          }
        }
      }
    }

    // Look for deleted services and invalidate these
    if (printServices != null) {
      for (int j = 0; j < printServices.length; j++) {
        if ((printServices[j] instanceof Win32PrintService)
            && (!printServices[j].equals(defaultPrintService))) {
          ((Win32PrintService) printServices[j]).invalidateService();
        }
      }
    }
    printServices = newServices;
  }
Example #11
0
  @Override
  public void print() {

    try {
      File input = new File(absoluteFilePath);
      FileInputStream fis = new FileInputStream(input);
      FileChannel fc = fis.getChannel();
      ByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());

      PDFFile curFile = null;
      PDFPrintPage pages = null;
      curFile = new PDFFile(bb); // Create PDF Print Page
      pages = new PDFPrintPage(curFile);
      PrinterJob pjob = PrinterJob.getPrinterJob();

      PrintService[] services = PrinterJob.lookupPrintServices();
      for (PrintService ps : services) {
        String pName = ps.getName();
        if (pName.equals(Profile.getInstance().getDefaultPrinterName())) {
          pjob.setPrintService(ps);
          logger.debug("Printing on : " + pName);
          break;
        }
      }

      pjob.setJobName(absoluteFilePath);
      Book book = new Book();
      PageFormat pformat = PrinterJob.getPrinterJob().defaultPage();
      book.append(pages, pformat, curFile.getNumPages());
      pjob.setPageable(book);

      // print
      PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();

      // Print it
      pjob.print(aset);
      fis.close();
    } catch (Exception e) {
      logger.error("Cannot print pdf", e);
      Dialog.showThrowable("Erreur", "Impossible d'imprimer le fichier", e);
    }
  }
 /* Want the PrintService which is default print service to have
  * equality of reference with the equivalent in list of print services
  * This isn't required by the API and there's a risk doing this will
  * lead people to assume its guaranteed.
  */
 public PrintService[] getPrintServices() {
   SecurityManager security = System.getSecurityManager();
   if (security != null) {
     security.checkPrintJobAccess();
   }
   if (printServices == null) {
     PrintService defService = getDefaultPrintService();
     printers = getAllPrinterNames();
     if (printers == null) {
       return new PrintService[0];
     }
     printServices = new PrintService[printers.length];
     for (int p = 0; p < printers.length; p++) {
       if (defService != null && printers[p].equals(defService.getName())) {
         printServices[p] = defService;
       } else {
         printServices[p] = new Win32PrintService(printers[p]);
       }
     }
   }
   return printServices;
 }
Example #13
0
  // set it protected to make it testable
  private IPrintingService getPrintingService(final I_AD_PrinterRouting route) {
    if (LogManager.isLevelFine()) {
      log.debug("Checking route: " + route);
    }

    final I_AD_Printer printer = route.getAD_Printer();
    if (LogManager.isLevelFine()) {
      log.debug("Printer: " + printer.getPrinterName());
    }

    final PrintService systemPrintService = getSystemPrintService(printer.getPrinterName());
    if (systemPrintService == null) {
      log.info("Printer not found in system: " + printer.getPrinterName());
      return null;
    }
    if (LogManager.isLevelFine()) {
      log.debug("System Print Service: " + systemPrintService);
    }

    final String printerName = systemPrintService.getName();
    Boolean isDirectPrint = null;
    if (isDirectPrint == null && route.getIsDirectPrint() != null) {
      isDirectPrint = X_AD_PrinterRouting.ISDIRECTPRINT_Yes.equals(route.getIsDirectPrint());
      if (LogManager.isLevelFine()) {
        log.debug("IsDirectPrint: " + isDirectPrint + " (From: " + route + ")");
      }
    }
    if (isDirectPrint == null) {
      isDirectPrint = isDirectPrint(printer);
    }

    final PrintingServiceImpl printingService =
        new PrintingServiceImpl(printerName, printer.getPrinterType(), isDirectPrint);

    if (LogManager.isLevelFine()) {
      log.debug("Printing Service: " + printingService);
    }
    return printingService;
  }
  /**
   * Fix for bug ID 6255588 from Sun bug database
   *
   * @param job print job that the fix applies to
   */
  public static void initPrinterJobFields(PrinterJob job) {
    try {
      PrintService[] printServices = PrintServiceLookup.lookupPrintServices(null, null);
      PrintService printService = PrintServiceLookup.lookupDefaultPrintService();

      String printerName = PrintConfig.getOsReceiptPrinterName();
      if (printToKitchen) {
        printerName = PrintConfig.getOsKitchenPrinterName();
      }

      for (int i = 0; i < printServices.length; i++) {
        PrintService service = printServices[i];
        if (service.getName().equals(printerName)) {
          printService = service;
          break;
        }
      }

      job.setPrintService(printService);
      printToKitchen = false;
    } catch (PrinterException e) {
    }
  }
  public synchronized PrintService getDefaultPrintService() {
    SecurityManager security = System.getSecurityManager();
    if (security != null) {
      security.checkPrintJobAccess();
    }

    // Windows does not have notification for a change in default
    // so we always get the latest.
    defaultPrinter = peer.getDefaultPrinterName();
    if (defaultPrinter == null) {
      return null;
    }

    if ((defaultPrintService != null) && defaultPrintService.getName().equals(defaultPrinter)) {

      return defaultPrintService;
    }

    // Not the same as default so proceed to get new PrintService.

    // clear defaultPrintService
    defaultPrintService = null;

    if (printServices != null) {
      for (int j = 0; j < printServices.length; j++) {
        if (defaultPrinter.equals(printServices[j].getName())) {
          defaultPrintService = printServices[j];
          break;
        }
      }
    }

    if (defaultPrintService == null) {
      defaultPrintService = new Win32PrintService(defaultPrinter, peer);
    }
    return defaultPrintService;
  }
Example #16
0
 public String getName() {
   return service.getName();
 }
  private void createTopSectionItems(Composite group3) {
    GridData gridData1 = new GridData();
    gridData1.horizontalAlignment = GridData.FILL;
    gridData1.grabExcessHorizontalSpace = true;
    gridData1.verticalAlignment = GridData.CENTER;
    GridData gridData = new GridData();
    gridData.horizontalAlignment = GridData.FILL;
    gridData.grabExcessHorizontalSpace = true;
    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 3;
    gridLayout.makeColumnsEqualWidth = false;
    Composite composite3 = toolkit.createComposite(group3, SWT.NONE);
    composite3.setLayout(gridLayout);
    composite3.setLayoutData(gridData);
    new Label(composite3, SWT.NONE).setText(Messages.PatientLabelEntryForm_title_label);

    projectTitleText = new BgcBaseText(composite3, SWT.BORDER);
    projectTitleText.setLayoutData(gridData);
    projectTitleText.setTextLimit(12);
    projectTitleText.setText(perferenceStore.getString(PreferenceConstants.PROJECT_TITLE));

    new Label(composite3, SWT.NONE);
    new Label(composite3, SWT.NONE).setText(Messages.PatientLabelEntryForm_logo_label);
    logoText = new BgcBaseText(composite3, SWT.BORDER);
    logoText.setEditable(false);
    logoText.setLayoutData(gridData1);
    logoText.setText(perferenceStore.getString(PreferenceConstants.LOGO_FILE_LOCATION));
    logoButton = new Button(composite3, SWT.NONE);
    logoButton.setText(Messages.PatientLabelEntryForm_browse);
    logoButton.addSelectionListener(
        new SelectionListener() {
          @Override
          public void widgetSelected(SelectionEvent event) {

            FileDialog fd = new FileDialog(shell, SWT.OPEN);
            fd.setText(Messages.PatientLabelEntryForm_select_logo_msg);
            String[] filterExt = {"*.png"}; // $NON-NLS-1$
            fd.setFilterExtensions(filterExt);
            String selected = fd.open();
            if (selected != null) {
              logoText.setText(selected);
            }
          }

          @Override
          public void widgetDefaultSelected(SelectionEvent event) {
            widgetSelected(event);
          }
        });

    GridData gridData21 = new GridData();
    gridData21.grabExcessHorizontalSpace = true;
    gridData21.verticalAlignment = GridData.CENTER;
    gridData21.horizontalAlignment = GridData.FILL;

    new Label(composite3, SWT.NONE).setText(Messages.PatientLabelEntryForm_template_label);
    templateCombo = new Combo(composite3, SWT.DROP_DOWN | SWT.BORDER | SWT.READ_ONLY);
    templateCombo.setLayoutData(gridData21);
    templateCombo.addSelectionListener(
        new SelectionListener() {

          @Override
          public void widgetSelected(SelectionEvent e) {

            loadSelectedTemplate();
          }

          @Override
          public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
          }
        });

    new Label(composite3, SWT.NONE);
    printerText =
        this.createReadOnlyLabelledField(
            composite3, SWT.NONE, Messages.PatientLabelEntryForm_intended_printer_label);

    new Label(composite3, SWT.NONE);
    new Label(composite3, SWT.NONE).setText(Messages.PatientLabelEntryForm_printer_label);

    printerCombo = new Combo(composite3, SWT.DROP_DOWN | SWT.BORDER | SWT.READ_ONLY);
    printerCombo.setLayoutData(gridData21);

    PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);

    for (PrintService ps : services) {
      printerCombo.add(ps.getName());
    }
    if (printerCombo.getItemCount() > 0) printerCombo.select(0);

    for (int i = 0; i < printerCombo.getItemCount(); i++) {
      if (printerCombo
          .getItem(i)
          .equals(perferenceStore.getString(PreferenceConstants.PRINTER_NAME))) {
        printerCombo.select(i);
        break;
      }
    }
    loadSelectedTemplate();
  }
Example #18
0
  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();
  }