Example usage for javax.print.attribute.standard PrinterName PrinterName

List of usage examples for javax.print.attribute.standard PrinterName PrinterName

Introduction

In this page you can find the example usage for javax.print.attribute.standard PrinterName PrinterName.

Prototype

public PrinterName(String printerName, Locale locale) 

Source Link

Document

Constructs a new printer name attribute with the given name and locale.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);
    PrintService service = PrintServiceLookup.lookupDefaultPrintService();

    services = PrintServiceLookup.lookupPrintServices(DocFlavor.INPUT_STREAM.GIF, null);

    AttributeSet aset = new HashAttributeSet();
    aset.add(new PrinterName("HP LaserJet", null));
    services = PrintServiceLookup.lookupPrintServices(null, aset);

    aset = new HashAttributeSet();
    aset.add(ColorSupported.SUPPORTED);
    services = PrintServiceLookup.lookupPrintServices(null, aset);

}

From source file:ru.codemine.pos.service.kkm.template.JasperChequeTemplate.java

public void print(Cheque cheque, String printerName) throws JRException {
    List<JasperChequeRecord> records = new ArrayList<>();

    for (ChequeLine line : cheque.getContent()) {
        records.add(new JasperChequeRecord(line.getProduct().getName(), line.getQuantity(),
                "=" + line.getLineTotal()));
    }/*from  w  w w.  j  av a2s  . c om*/

    Map<String, Object> parameters = new HashMap<>();
    parameters.put("titleString", cheque.getShop().getOrgName());
    parameters.put("reqs",
            "?? " + cheque.getShop().getOrgInn() + "    " + cheque.getShop().getOrgKpp());
    parameters.put("currentTime", DateTime.now().toString("dd.MM.YY HH:mm"));
    parameters.put("currentUser", cheque.getCreator().getUsername());
    parameters.put("chequeNumber", "#0011");
    parameters.put("chequeTotal", "=" + cheque.getChequeTotal());
    parameters.put("paymentType", Cheque.getAvaiblePaymentTypes().get(cheque.getPaymentType()));
    parameters.put("fromClient", cheque.getChequeTotal().toString());
    parameters.put("toClient", "0.0");

    JasperReport report = (JasperReport) JRLoader.loadObjectFromFile("reports/ChequeTemplate.jasper");
    JRBeanCollectionDataSource dataSource = new JRBeanCollectionDataSource(records);
    JasperPrint jasperPrint = JasperFillManager.fillReport(report, parameters, dataSource);

    PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();

    PrintServiceAttributeSet printServiceAttributeSet = new HashPrintServiceAttributeSet();
    printServiceAttributeSet.add(new PrinterName(printerName, null));

    JRPrintServiceExporter exporter = new JRPrintServiceExporter();
    exporter.setExporterInput(new SimpleExporterInput(jasperPrint));

    SimplePrintServiceExporterConfiguration configuration = new SimplePrintServiceExporterConfiguration();
    configuration.setPrintRequestAttributeSet(printRequestAttributeSet);
    configuration.setPrintServiceAttributeSet(printServiceAttributeSet);
    configuration.setDisplayPageDialog(false);
    configuration.setDisplayPrintDialog(false);

    exporter.setConfiguration(configuration);
    exporter.exportReport();

}

From source file:org.efaps.tests.Printer.java

/**
 * @param args/*  ww  w .  j  a v a  2 s .c o  m*/
 */
public static void main(final String[] args) {
    final AttributeSet aset = new HashAttributeSet();
    aset.add(new PrinterName("HP-LaserJet-100-colorMFP-M175nw", null));
    final PrintService[] pservices = PrintServiceLookup.lookupPrintServices(null, aset);
    for (final PrintService serv : pservices) {
        System.out.println(serv);
    }

    try {
        final PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
        // pras.add(new Copies(2));

        final PrintService pservice = getPrintService4Name("HP-LaserJet-100-colorMFP-M175nw");
        pservice.getSupportedDocFlavors();
        final DocPrintJob job = pservice.createPrintJob();

        final DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
        final String filename = "/home/janmoxter/Downloads/Notas_de_Pedido_null.DOCX";
        final FileInputStream fis = new FileInputStream(filename);
        final DocAttributeSet das = new HashDocAttributeSet();
        final Doc doc = new SimpleDoc(fis, flavor, das);
        job.print(doc, pras);
    } catch (final FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (final PrintException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:org.openvpms.report.jasper.AbstractJasperIMReport.java

/**
 * Prints a {@code JasperPrint} to a printer.
 *
 * @param print      the object to print
 * @param properties the print properties
 * @throws ReportException if {@code print} contains no pages
 * @throws JRException     for any error
 *///  w  w  w . java  2s .  c o m
private void print(JasperPrint print, PrintProperties properties) throws JRException {
    if (print.getPages().isEmpty()) {
        throw new ReportException(NoPagesToPrint);
    }
    if (log.isDebugEnabled()) {
        log.debug("PrinterName: " + properties.getPrinterName());
    }

    JRPrintServiceExporter exporter = new JRPrintServiceExporter();
    exporter.setExporterInput(new SimpleExporterInput(print));
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    aset.add(new Copies(properties.getCopies()));
    MediaSizeName mediaSize = properties.getMediaSize();
    OrientationRequested orientation = properties.getOrientation();
    MediaTray tray = properties.getMediaTray();
    Sides sides = properties.getSides();
    if (mediaSize != null) {
        if (log.isDebugEnabled()) {
            log.debug("MediaSizeName: " + mediaSize);
        }
        aset.add(mediaSize);
    }
    if (orientation != null) {
        if (log.isDebugEnabled()) {
            log.debug("Orientation: " + orientation);
        }
        aset.add(orientation);
    }
    if (tray != null) {
        if (log.isDebugEnabled()) {
            log.debug("MediaTray: " + tray);
        }
        aset.add(tray);
    }
    if (sides != null) {
        if (log.isDebugEnabled()) {
            log.debug("Sides: " + sides);
        }
        aset.add(sides);
    }
    SimplePrintServiceExporterConfiguration printConfiguration = new SimplePrintServiceExporterConfiguration();
    printConfiguration.setPrintRequestAttributeSet(aset);
    // set the printer name
    PrintServiceAttributeSet serviceAttributeSet = new HashPrintServiceAttributeSet();
    serviceAttributeSet.add(new PrinterName(properties.getPrinterName(), null));
    printConfiguration.setPrintServiceAttributeSet(serviceAttributeSet);
    exporter.setConfiguration(printConfiguration);
    // print it
    exporter.exportReport();
}

From source file:org.openvpms.web.component.im.till.CashDrawer.java

/**
 * Opens the drawer.//  w  w  w  . ja  v a  2s .  c  o  m
 *
 * @throws PrintException if the drawer cannot be opened
 */
public void open() throws PrintException {
    AttributeSet attrSet = new HashPrintServiceAttributeSet(new PrinterName(printer, null));
    PrintService[] printServices = PrintServiceLookup.lookupPrintServices(null, attrSet);
    if (printServices.length == 0) {
        throw new PrintException(Messages.format("till.drawerCommand.printernotfound", printer));
    }
    DocPrintJob job = printServices[0].createPrintJob();
    DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
    Doc doc = new SimpleDoc(command, flavor, null);
    job.print(doc, null);
}

From source file:us.mn.state.health.lims.common.provider.reports.SampleLabelPrintProvider.java

private String validateInput(String accessionCount, String accessionStart, String accessionEnd,
        String printerName, String masterLabels, String itemLabels) {
    if ((StringUtil.isNullorNill(accessionCount) && StringUtil.isNullorNill(accessionStart)
            && StringUtil.isNullorNill(accessionEnd)) || StringUtil.isNullorNill(printerName)
            || StringUtil.isNullorNill(masterLabels) || "0".equals(masterLabels))
        return FWD_FAIL;

    masterCount = Integer.parseInt(masterLabels);
    itemCount = StringUtil.isNullorNill(itemLabels) ? 0 : Integer.parseInt(itemLabels);

    //bugzilla 2374 limit number of labels
    int maxNumberOfLabels = Integer.parseInt(SystemConfiguration.getInstance().getMaxNumberOfLabels());
    if (masterCount > maxNumberOfLabels || itemCount > maxNumberOfLabels) {
        LogEvent.logError("SampleLabelPrintProvider", "printLabels()",
                StringUtil.getMessageForKey("errors.labelprint.exceeded.maxnumber",
                        SystemConfiguration.getInstance().getMaxNumberOfLabels()));
        return FWD_FAIL_MAX_LABELS_EXCEED;
    }// w  w  w .ja v a2s.  com

    //validate printer
    PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);
    String printer = null;
    PrinterName printerToUse = new PrinterName(printerName, null);

    for (int i = 0; i < services.length; i++) {
        printer = services[i].getName();
        if (printer.equalsIgnoreCase(printerToUse.toString())) {
            //System.out.println("This is the printer I will use "
            //+ printerName);
            ps = services[i];
            //bugzilla 2380: load all valid printer names for error message
            //break;
        }
    }

    if (ps == null) {
        LogEvent.logError("SampleLabelPrintProvider", "printLabels()",
                StringUtil.getMessageForKey("errors.labelprint.no.printer"));
        return FWD_FAIL_BAD_PRINTER;
    }

    return FWD_SUCCESS;
}