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

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

Introduction

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

Prototype

public Copies(int value) 

Source Link

Document

Construct a new copies attribute with the given integer value.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {

    // Set up the attribute set
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    aset.add(new Copies(2));

}

From source file:Main.java

static public void main(String args[]) throws Exception {
    PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
    pras.add(new Copies(1));

    PrintService pss[] = PrintServiceLookup.lookupPrintServices(DocFlavor.INPUT_STREAM.GIF, pras);

    if (pss.length == 0)
        throw new RuntimeException("No printer services available.");

    PrintService ps = pss[0];//from www . j  a  va2  s . c  om
    System.out.println("Printing to " + ps);

    DocPrintJob job = ps.createPrintJob();

    FileInputStream fin = new FileInputStream("YOurImageFileName.PNG");
    Doc doc = new SimpleDoc(fin, DocFlavor.INPUT_STREAM.GIF, null);

    job.print(doc, pras);

    fin.close();
}

From source file:PrintImage.java

static public void main(String args[]) throws Exception {
    PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
    pras.add(new Copies(1));
    PrintService pss[] = PrintServiceLookup.lookupPrintServices(DocFlavor.INPUT_STREAM.GIF, pras);
    if (pss.length == 0)
        throw new RuntimeException("No printer services available.");
    PrintService ps = pss[0];/*from ww w. j  a  va 2 s .  com*/
    System.out.println("Printing to " + ps);
    DocPrintJob job = ps.createPrintJob();
    FileInputStream fin = new FileInputStream("YOurImageFileName.PNG");
    Doc doc = new SimpleDoc(fin, DocFlavor.INPUT_STREAM.GIF, null);
    job.print(doc, pras);
    fin.close();
}

From source file:PrintImage.java

static public void main(String args[]) throws Exception {
    try {/*from w ww. j  av a2  s .c o  m*/
        PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
        pras.add(new Copies(1));

        PrintService pss[] = PrintServiceLookup.lookupPrintServices(DocFlavor.INPUT_STREAM.GIF, pras);

        if (pss.length == 0)
            throw new RuntimeException("No printer services available.");

        PrintService ps = pss[0];
        System.out.println("Printing to " + ps);

        DocPrintJob job = ps.createPrintJob();

        FileInputStream fin = new FileInputStream("YOurImageFileName.PNG");
        Doc doc = new SimpleDoc(fin, DocFlavor.INPUT_STREAM.GIF, null);

        job.print(doc, pras);

        fin.close();
    } catch (IOException ie) {
        ie.printStackTrace();
    } catch (PrintException pe) {
        pe.printStackTrace();
    }
}

From source file:Print.java

public static void main(String[] args) throws IOException {
    // These are values we'll set from the command-line arguments
    boolean query = false;
    String printerName = null;//from   w  ww  .ja  va 2 s. c  o m
    String inputFileName = null;
    String outputFileName = null;
    String outputFileType = null;
    PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();

    // Loop through the arguments
    for (int i = 0; i < args.length; i++) {
        if (args[i].equals("-q"))
            query = true; // Is this is query?
        else if (args[i].equals("-p")) // Specific printer name
            printerName = args[++i];
        else if (args[i].equals("-i")) // The file to print
            inputFileName = args[++i];
        else if (args[i].equals("-ps")) { // Print it to this file
            // Sun's Java 1.4 implementation only supports PostScript
            // output. Other implementations might offer PDF, for example.
            outputFileName = args[++i];
            outputFileType = "application/postscript";
        }
        // The rest of the arguments represent common printing attributes
        else if (args[i].equals("-color")) // Request a color printer
            attributes.add(Chromaticity.COLOR);
        else if (args[i].equals("-landscape")) // Request landscape mode
            attributes.add(OrientationRequested.LANDSCAPE);
        else if (args[i].equals("-letter")) // US Letter-size paper
            attributes.add(MediaSizeName.NA_LETTER);
        else if (args[i].equals("-a4")) // European A4 paper
            attributes.add(MediaSizeName.ISO_A4);
        else if (args[i].equals("-staple")) // Request stapling
            attributes.add(Finishings.STAPLE);
        else if (args[i].equals("-collate")) // Collate multiple copies
            attributes.add(SheetCollate.COLLATED);
        else if (args[i].equals("-duplex")) // Request 2-sided
            attributes.add(Sides.DUPLEX);
        else if (args[i].equals("-2")) // 2 pages to a sheet
            attributes.add(new NumberUp(2));
        else if (args[i].equals("-copies")) // how many copies
            attributes.add(new Copies(Integer.parseInt(args[++i])));
        else {
            System.out.println("Unknown argument: " + args[i]);
            System.exit(1);
        }
    }

    if (query) {
        // If the -q argument was specified, but no printer was named,
        // then list all available printers that can support the attributes
        if (printerName == null)
            queryServices(attributes);
        // Otherwise, look for a named printer that can support the
        // attributes and print its status
        else
            queryPrinter(printerName, attributes);
    } else if (outputFileName != null)
        // If this is not a query and we have a filename, print to a file
        printToFile(outputFileName, outputFileType, inputFileName, attributes);
    else
        // Otherwise, print to the named printer, or to the default
        // printer otherwise.
        print(printerName, inputFileName, attributes);

    // The main() method ends here, but there may be a printing thread
    // operating in the background. So the program may not terminate
    // until printing completes.
}

From source file:net.sourceforge.fenixedu.util.report.ReportsUtils.java

private static void print(PrintService printService, byte[] pdf) throws PrintException {
    final DocPrintJob job = printService.createPrintJob();
    final Doc doc = new SimpleDoc(pdf, DocFlavor.BYTE_ARRAY.PDF, null);

    final PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    aset.add(new Copies(1));
    aset.add(MediaSizeName.ISO_A4);
    aset.add(Sides.ONE_SIDED);//from  ww w.  ja  va  2  s.c  o  m

    job.print(doc, aset);
}

From source file:de.cenote.jasperstarter.Report.java

public void print() throws JRException {
    PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();
    //printRequestAttributeSet.add(MediaSizeName.ISO_A4);
    if (config.hasCopies()) {
        printRequestAttributeSet.add(new Copies(config.getCopies().intValue()));
    }/*from w  w w.  j  a v  a 2 s.c  o m*/
    PrintServiceAttributeSet printServiceAttributeSet = new HashPrintServiceAttributeSet();
    //printServiceAttributeSet.add(new PrinterName("Fax", null));
    JRPrintServiceExporter exporter = new JRPrintServiceExporter();
    if (config.hasReportName()) {
        jasperPrint.setName(config.getReportName());
    }
    exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
    SimplePrintServiceExporterConfiguration expConfig = new SimplePrintServiceExporterConfiguration();
    if (config.hasPrinterName()) {
        String printerName = config.getPrinterName();
        PrintService service = Printerlookup.getPrintservice(printerName, Boolean.TRUE, Boolean.TRUE);
        expConfig.setPrintService(service);
        if (config.isVerbose()) {
            System.out.println("printer-name: "
                    + ((service == null) ? "No printer found with name \"" + printerName + "\"! Using default."
                            : "found: " + service.getName()));
        }
    }
    //exporter.setParameter(JRExporterParameter.PAGE_INDEX, pageIndex);
    //exporter.setParameter(JRExporterParameter.START_PAGE_INDEX, pageStartIndex);
    //exporter.setParameter(JRExporterParameter.END_PAGE_INDEX, pageEndIndex);
    expConfig.setPrintRequestAttributeSet(printRequestAttributeSet);
    expConfig.setPrintServiceAttributeSet(printServiceAttributeSet);
    expConfig.setDisplayPageDialog(Boolean.FALSE);
    if (config.isWithPrintDialog()) {
        setLookAndFeel();
        expConfig.setDisplayPrintDialog(Boolean.TRUE);
    } else {
        expConfig.setDisplayPrintDialog(Boolean.FALSE);
    }
    exporter.setConfiguration(expConfig);
    exporter.exportReport();
}

From source file:com.sos.jitl.jasperreports.JobSchedulerJasperReportJob.java

/**
 * Dokument drucken./*  www  .ja  v  a2  s.c  o  m*/
 * 
 * @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:edu.ku.brc.specify.ui.containers.ContainerTreePanel.java

/**
 * @param actionableTree/*  www. ja  va 2  s  .  c  om*/
 */
public void print(final JTree actionableTree) {
    /*if (true)
    {
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    aset.add(OrientationRequested.LANDSCAPE);
    aset.add(new Copies(2));
    aset.add(new JobName("My job", null));
            
    // Create a print job 
    PrinterJob pj = PrinterJob.getPrinterJob();       
    pj.setPrintable(this);
    // locate a print service that can handle the request 
    PrintService[] services =
        PrinterJob.lookupPrintServices();
            
    if (services.length > 0) {
        System.out.println("selected printer " + services[0].getName());
        try {
            pj.setPrintService(services[0]);
            pj.pageDialog(aset);
            if(pj.printDialog(aset)) {
                pj.print(aset);
            }
        } catch (PrinterException pe) { 
            System.err.println(pe);
        }
    }
    return;
    }*/

    DefaultMutableTreeNode clonedTree = GhostActionableTree
            .makeDeepCopy((DefaultMutableTreeNode) actionableTree.getModel().getRoot());
    GhostActionableTree printTree = new GhostActionableTree(this, new DefaultTreeModel(clonedTree));
    printTree.setRowHeight(ROW_HEIGHT);
    //printTree.setEditable(false);
    //printTree.setVisibleRowCount(15);
    ContainerTreeRenderer renderer = new ContainerTreeRenderer(null, false, false);
    renderer.setBGColor(Color.WHITE);
    renderer.setFont(getFont().deriveFont(8.0f));
    //renderer.setLeafIcon(IconManager.getIcon(CollectionObject.class.getSimpleName(), IconManager.IconSize.Std32));
    //renderer.setVerticalTextPosition(SwingConstants.CENTER);
    printTree.setCellRenderer(renderer);

    for (int row = 0; row < printTree.getRowCount(); row++) {
        printTree.expandRow(row);
    }

    PrintablePanel p = new PrintablePanel(new BorderLayout(), printTree);
    p.add(printTree, BorderLayout.CENTER);

    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    //PrinterResolution        pr   = new PrinterResolution(300, 300, PrinterResolution.DPI);
    //MediaPrintableArea       mpa  = new MediaPrintableArea(8,21, 210-16, 296-42, MediaPrintableArea.MM);

    //aset.add( MediaSizeName.IS);
    //aset.add( pr );
    //aset.add( mpa );
    aset.add(new Copies(1));
    aset.add(OrientationRequested.PORTRAIT);
    aset.add(PrintQuality.HIGH);

    PrinterJob job = PrinterJob.getPrinterJob();
    /*PageFormat pageFormat = job.defaultPage();
    Paper      paper      = pageFormat.getPaper();
    paper.setSize(pageFormat.getWidth(), pageFormat.getHeight());
    paper.setImageableArea(
    0,
    0,
    pageFormat.getWidth(),
    pageFormat.getHeight()
    );
    //aset.add( Fidelity.FIDELITY_TRUE );
    pageFormat.setPaper(paper);
            
    Book book = new Book();
    book.append(p, pageFormat, 1);
    job.setPageable(book);*/

    job.setPrintable(p);
    boolean ok = job.printDialog();
    if (ok) {
        try {
            job.print(aset);

        } catch (PrinterException ex) {
            ex.printStackTrace();
            /* The job did not successfully complete */
        }
    }
}

From source file:org.apache.camel.component.printer.PrinterOperations.java

public PrinterOperations() throws PrintException {
    printService = PrintServiceLookup.lookupDefaultPrintService();
    if (printService == null) {
        throw new PrintException("Printer lookup failure. No default printer set up for this host");
    }/*from  w  ww  . jav a 2 s.com*/
    job = printService.createPrintJob();
    flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
    printRequestAttributeSet = new HashPrintRequestAttributeSet();
    printRequestAttributeSet.add(new Copies(1));
    printRequestAttributeSet.add(MediaSizeName.NA_LETTER);
    printRequestAttributeSet.add(Sides.ONE_SIDED);
}