Example usage for javax.print.attribute PrintServiceAttributeSet add

List of usage examples for javax.print.attribute PrintServiceAttributeSet add

Introduction

In this page you can find the example usage for javax.print.attribute PrintServiceAttributeSet add.

Prototype

public boolean add(Attribute attribute);

Source Link

Document

Adds the specified attribute value to this attribute set if it is not already present, first removing any existing value in the same attribute category as the specified attribute value (optional operation).

Usage

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()));
    }/*  ww  w  . j  a v a 2  s . 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:com.sos.jitl.jasperreports.JobSchedulerJasperReportJob.java

/**
 * Dokument drucken./*from w ww.jav  a2 s  .com*/
 * 
 * @throws Exception
 */
private String printDocument() throws Exception {
    try {
        //         druckername bestimmen
        String prName = getPrinter();
        if (sosString.parseToString(prName).length() > 0) {
            JasperPrint jasperPrint = (JasperPrint) JRLoader.loadObject(filledReportFile);
            net.sf.jasperreports.engine.export.JRPrintServiceExporter exporter = new net.sf.jasperreports.engine.export.JRPrintServiceExporter();
            //            set the report to print
            exporter.setParameter(
                    net.sf.jasperreports.engine.export.JRPrintServiceExporterParameter.JASPER_PRINT,
                    jasperPrint);
            //            count of report to print            
            javax.print.attribute.PrintRequestAttributeSet aset = new javax.print.attribute.HashPrintRequestAttributeSet();
            aset.add(new Copies(getPrinterCopies()));
            aset.add(MediaSizeName.ISO_A4);
            exporter.setParameter(
                    net.sf.jasperreports.engine.export.JRPrintServiceExporterParameter.PRINT_REQUEST_ATTRIBUTE_SET,
                    aset);
            //            let the exporter know which printer we want to print on
            javax.print.attribute.PrintServiceAttributeSet serviceAttributeSet = new javax.print.attribute.HashPrintServiceAttributeSet();
            serviceAttributeSet.add(new javax.print.attribute.standard.PrinterName(prName, null));
            exporter.setParameter(
                    net.sf.jasperreports.engine.export.JRPrintServiceExporterParameter.PRINT_SERVICE_ATTRIBUTE_SET,
                    serviceAttributeSet);
            //            print it
            exporter.exportReport();
            spooler_log.info("..report successfully printed " + getPrinterCopies() + "x.");
            return "..report successfully printed " + getPrinterCopies() + "x.";
        }
        return "";
    } catch (Exception e) {
        throw new Exception("..error in " + SOSClassUtil.getMethodName() + " " + e);
    }
}

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
 *//*from  www  . j  av a2 s.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();
}