Example usage for javax.print.attribute HashPrintRequestAttributeSet HashPrintRequestAttributeSet

List of usage examples for javax.print.attribute HashPrintRequestAttributeSet HashPrintRequestAttributeSet

Introduction

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

Prototype

public HashPrintRequestAttributeSet() 

Source Link

Document

Construct a new, empty print request attribute set.

Usage

From source file:org.openmrs.module.pharmacy.page.controller.PharmacyGroupPageController.java

void printOrder(int orderID) {

    try {//from   www.  j av a2s  .c o m
        DrugOrder order = (DrugOrder) Context.getOrderService().getOrder(orderID);
        drugorders drugorder = Context.getService(drugordersService.class).getDrugOrderByOrderID(orderID);

        PrintService service = PrintServiceLookup.lookupDefaultPrintService();

        String OrderDetails = drugorder.getDrugName().getDisplayString() + " " + order.getDose() + " "
                + order.getDoseUnits().getDisplayString() + " " + order.getDuration() + " "
                + order.getDurationUnits().getDisplayString() + " " + order.getQuantity() + " "
                + order.getQuantityUnits() + "\n" + "Route: " + order.getRoute().getDisplayString() + " "
                + "Frequency: " + order.getFrequency().getName() + "\n" + "Start Date: "
                + drugorder.getStartDate().toString() + "\n" + "Patient Instructions: "
                + drugorder.getPatientInstructions();

        try (InputStream is = new ByteArrayInputStream(OrderDetails.getBytes())) {
            PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
            pras.add(new Copies(1));

            if (service != null) {
                DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
                Doc doc = new SimpleDoc(is, flavor, null);
                DocPrintJob job = service.createPrintJob();

                job.print(doc, pras);
            }
        }

    } catch (IOException | PrintException ex) {
        Logger.getLogger(PharmacyGroupPageController.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:org.openmrs.module.pharmacy.page.controller.PharmacySinglePageController.java

void printOrder(int orderID) {

    try {/*w w  w .j  a  v  a 2  s .  c o  m*/
        DrugOrder order = (DrugOrder) Context.getOrderService().getOrder(orderID);
        drugorders drugorder = Context.getService(drugordersService.class).getDrugOrderByOrderID(orderID);

        PrintService service = PrintServiceLookup.lookupDefaultPrintService();

        String OrderDetails = drugorder.getDrugName().getDisplayString() + " " + order.getDose() + " "
                + order.getDoseUnits().getDisplayString() + " " + order.getDuration() + " "
                + order.getDurationUnits().getDisplayString() + " " + order.getQuantity() + " "
                + order.getQuantityUnits() + "\n" + "Route: " + order.getRoute().getDisplayString() + " "
                + "Frequency: " + order.getFrequency().getName() + "\n" + "Start Date: "
                + drugorder.getStartDate().toString() + "\n" + "Patient Instructions: "
                + drugorder.getPatientInstructions();

        InputStream is = new ByteArrayInputStream(OrderDetails.getBytes());

        PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
        pras.add(new Copies(1));

        if (service != null) {
            DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
            Doc doc = new SimpleDoc(is, flavor, null);
            DocPrintJob job = service.createPrintJob();

            job.print(doc, pras);
        }
        is.close();

    } catch (IOException | PrintException ex) {
        Logger.getLogger(PharmacySinglePageController.class.getName()).log(Level.SEVERE, null, ex);
    }
}

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 ww  w .  j  a  v 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();
}

From source file:org.pentaho.reporting.engine.classic.extensions.modules.java14print.Java14PrintUtil.java

/**
 * This method replaces the media definition from the given attribute set with the one found in the report itself.
 * <p/>// w  w w  . j  a v a  2  s.  c om
 * If no JobName is set, a default jobname will be assigned.
 *
 * @param attributes
 * @param report
 * @return
 */
public static PrintRequestAttributeSet copyConfiguration(PrintRequestAttributeSet attributes,
        final MasterReport report) {
    if (attributes == null) {
        attributes = new HashPrintRequestAttributeSet();
    }

    // for now, be lazy, assume that the first page is the reference
    final PageDefinition pdef = report.getPageDefinition();
    final PageFormat format = pdef.getPageFormat(0);
    final Paper paper = format.getPaper();

    final Media media = MediaSize.findMedia((float) (paper.getWidth() / POINTS_PER_INCH),
            (float) (paper.getHeight() / POINTS_PER_INCH), Size2DSyntax.INCH);
    attributes.add(media);

    final MediaPrintableArea printableArea = new MediaPrintableArea(
            (float) (paper.getImageableX() / POINTS_PER_INCH),
            (float) (paper.getImageableY() / POINTS_PER_INCH),
            (float) (paper.getImageableWidth() / POINTS_PER_INCH),
            (float) (paper.getImageableHeight() / POINTS_PER_INCH), Size2DSyntax.INCH);

    attributes.add(printableArea);
    attributes.add(mapOrientation(format.getOrientation()));

    return attributes;
}

From source file:org.pentaho.reporting.engine.classic.extensions.modules.java14print.Java14PrintUtil.java

public static PrintRequestAttributeSet copyAuxillaryAttributes(PrintRequestAttributeSet attributes,
        final MasterReport report) {
    if (attributes == null) {
        attributes = new HashPrintRequestAttributeSet();
    }//from w w  w.  j a  v  a  2s  .com

    if (attributes.containsKey(JobName.class) == false) {
        final String jobName = report.getReportConfiguration().getConfigProperty(PrintUtil.PRINTER_JOB_NAME_KEY,
                report.getTitle());
        if (jobName != null) {
            attributes.add(new JobName(jobName, null));
        }
    }
    if (attributes.containsKey(Copies.class) == false) {
        final int numberOfCopies = PrintUtil.getNumberOfCopies(report.getReportConfiguration());
        attributes.add(new Copies(numberOfCopies));
    }

    return attributes;
}

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

private void runPrintJobs() throws PrintException {
    returnedData += ";;";

    if (masterCount > 0) {
        DocPrintJob masterJob = ps.createPrintJob();

        PrintRequestAttributeSet masterAset = new HashPrintRequestAttributeSet();
        masterAset.add(new Copies(masterCount));

        String masterLabel = "";
        String masterZPL = StringUtil.getMessageForKey("master.label.zpl.prefix"); //"^XA";
        for (Property prop : masterPrintOrder) {
            if (ConfigurationProperties.getInstance().isPropertyValueEqual(prop, "true")) {
                masterLabel += (!GenericValidator.isBlankOrNull(labelData.get(prop.name().toString()))
                        ? labelData.get(prop.name().toString())
                        : "") + "\n";
                if (prop.equals(Property.MASTER_LABELS_ACCESSION)) {
                    masterZPL += StringUtil.getMessageForKey("master.label.zpl.accession.barcode.prefix") //"^FO20,30^BCN,60,N,N,N^FD"
                            + labelData.get(prop.name().toString())
                            + StringUtil.getMessageForKey("master.label.zpl.accession.text.prefix") //"^FS^FO30,90^AEN,12,18^FD"
                            + labelData.get(prop.name().toString())
                            + StringUtil.getMessageForKey("master.label.zpl.accession.suffix"); //"^FS";
                } else {
                    masterZPL += StringUtil.getMessageForKey("master.label.zpl.other.prefix") //"^FO25,195^AEN,12,18^FD"
                            + labelData.get(prop.name().toString())
                            + StringUtil.getMessageForKey("master.label.zpl.other.suffix"); //"^FS";
                }/*from ww  w.  j  a  v a  2 s.  c  o m*/
            }
        }
        masterZPL += StringUtil.getMessageForKey("master.label.zpl.suffix"); //"^XZ";

        // Printing raw ZPL and returning the ZPL string that can be displayed via JavaScript as a simulated label in the browser
        //         System.out.println("Master Label (" + masterCount + " copies):\n" + masterLabel);
        //         System.out.println("Master Label ZPL (" + masterCount + " copies):\n" + masterZPL + "\n");
        returnedData += masterZPL;

        byte[] byt = masterZPL.getBytes();
        DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
        Doc doc = new SimpleDoc(byt, flavor, null);
        masterJob.addPrintJobListener(new MyPrintJobListener());
        masterJob.print(doc, masterAset);
    }

    returnedData += ";;";

    for (int j = 1; j <= itemCount; j++) {
        DocPrintJob itemJob = ps.createPrintJob();
        PrintRequestAttributeSet itemAset = new HashPrintRequestAttributeSet();
        itemAset.add(new Copies(1));

        String itemLabel = "";
        String itemZPL = StringUtil.getMessageForKey("item.label.zpl.prefix"); //"^XA";
        for (Property prop : itemPrintOrder) {
            if (ConfigurationProperties.getInstance().isPropertyValueEqual(prop, "true")) {
                itemLabel += !GenericValidator.isBlankOrNull(labelData.get(prop.name().toString()))
                        ? labelData.get(prop.name().toString())
                        : "";
                if (prop.equals(Property.SPECIMEN_LABELS_ACCESSION)) {
                    itemLabel += "-" + j;
                    itemZPL += StringUtil.getMessageForKey("item.label.zpl.accession.barcode.prefix") //"^FO20,30^BCN,60,N,N,N^FD"
                            + labelData.get(prop.name().toString()) + "-" + j
                            + StringUtil.getMessageForKey("item.label.zpl.accession.text.prefix") //"^FS^FO30,90^AEN,12,18^FD"
                            + labelData.get(prop.name().toString()) + "-" + j
                            + StringUtil.getMessageForKey("item.label.zpl.accession.suffix"); //"^FS";
                } else {
                    itemZPL += StringUtil.getMessageForKey("item.label.zpl.other.prefix") //"^FO25,195^AEN,12,18^FD"
                            + labelData.get(prop.name().toString())
                            + StringUtil.getMessageForKey("item.label.zpl.other.suffix"); //"^FS";
                }
                itemLabel += "\n";
            }
        }
        itemZPL += StringUtil.getMessageForKey("item.label.zpl.suffix"); //"^XZ";

        // Printing raw ZPL and returning a ZPL string that can be displayed via JavaScript as a simulated label in the browser
        //         System.out.println("Item Label:\n" + itemLabel);            
        //         System.out.println("Item Label ZPL:\n" + itemZPL + "\n");
        returnedData += "::" + itemZPL;

        byte[] byt = itemZPL.getBytes();
        DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
        Doc doc = new SimpleDoc(byt, flavor, null);
        itemJob.addPrintJobListener(new MyPrintJobListener());
        itemJob.print(doc, itemAset);
    }

    //String label = SystemConfiguration.getInstance()
    //      .getDefaultSampleLabel(accessionNumber);

    //byte[] byt = label.getBytes();
    //DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
    //Doc doc = new SimpleDoc(byt, flavor, null);
    //job.addPrintJobListener(new MyPrintJobListener());
    //job.print(doc, aset);
}

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

public void printBarcodeLabel(String[] accList) {
    try {/*from  ww  w. ja v a  2 s. co m*/

        // Support with 3 labels per row for now
        int itemsperrow = 3;

        String numberOfLabelCopiesString = null;
        int numberOfLabelCopies = 1;
        try {
            numberOfLabelCopiesString = SystemConfiguration.getInstance()
                    .getLabelNumberOfCopies("print.label.numberofcopies");
            numberOfLabelCopies = Integer.parseInt(numberOfLabelCopiesString);
        } catch (NumberFormatException nfe) {
            // System.out.println("numberOfLabelCopies not defined as
            // numeric");
        }

        String accessionNumber = "fail";// (String)

        int labelPerPatient = 1;
        try {
            labelPerPatient = masterCount;
        } catch (NumberFormatException nfe) {
            labelPerPatient = 1;
        }

        if (ps == null) {
            // System.out.println("Zebra printer is not found.");
            return;
        }

        ArrayList listAccessNumber = new ArrayList<>();

        for (int i = 0; i < accList.length; i++) {
            listAccessNumber.add(accList[i]);
        }

        ArrayList<String> newListAccessNumber = new ArrayList<String>();
        Iterator iter = listAccessNumber.iterator();
        while (iter.hasNext()) {
            String element = (String) iter.next();
            for (int i = 0; i < labelPerPatient; i++) {
                newListAccessNumber.add(element);
            }
        }
        int sizeListAcc = newListAccessNumber.size();

        if (sizeListAcc % itemsperrow != 0) {
            for (int i = 0; i < (itemsperrow - (sizeListAcc % itemsperrow)); i++) {
                newListAccessNumber.add("");
            }
        }
        String accessionNumber1 = "";
        String accessionNumber2 = "";
        String accessionNumber3 = "";

        for (int i = 0; i < newListAccessNumber.size(); i = i + itemsperrow) {
            accessionNumber1 = newListAccessNumber.get(i).toString();
            accessionNumber2 = newListAccessNumber.get(i + 1).toString();
            accessionNumber3 = newListAccessNumber.get(i + 2).toString();
            DocPrintJob job = ps.createPrintJob();
            PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
            //aset.add(new Copies(numberOfLabelCopies * labelPerPatient));
            aset.add(new Copies(numberOfLabelCopies * 1));
            String label = "";
            if (itemsperrow == 3) {
                label = SystemConfiguration.getInstance().getAllDefaultSampleLabel(accessionNumber1,
                        accessionNumber2, accessionNumber3);
                returnedData += label;
            } else {
                return;
            }
            System.out.println(returnedData);

            byte[] byt = label.getBytes();
            DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
            Doc doc = new SimpleDoc(byt, flavor, null);
            job.addPrintJobListener(new MyPrintJobListener());
            job.print(doc, aset);
            //System.out.println("success...");
        }

    } catch (Exception e) {
        System.out.println("Error in SampleLabelPrintProvider");
        e.printStackTrace();
    } finally {

    }
}