Example usage for java.awt.print PrinterJob setCopies

List of usage examples for java.awt.print PrinterJob setCopies

Introduction

In this page you can find the example usage for java.awt.print PrinterJob setCopies.

Prototype

public abstract void setCopies(int copies);

Source Link

Document

Sets the number of copies to be printed.

Usage

From source file:MainClass.java

public static void main(String[] args) {
    try {//from   w  ww.j  a  v a2s. c o  m
        PrinterJob pjob = PrinterJob.getPrinterJob();
        pjob.setJobName("Graphics Demo Printout");
        pjob.setCopies(1);
        pjob.setPrintable(new Printable() {
            public int print(Graphics pg, PageFormat pf, int pageNum) {
                if (pageNum > 0) // we only print one page
                    return Printable.NO_SUCH_PAGE; // ie., end of job

                pg.drawString("www.java2s.com", 10, 10);

                return Printable.PAGE_EXISTS;
            }
        });

        if (pjob.printDialog() == false) // choose printer
            return;
        pjob.print();
    } catch (PrinterException pe) {
        pe.printStackTrace();
    }
}

From source file:MainClass.java

public static void main(String[] args) {
    PrinterJob job = PrinterJob.getPrinterJob();

    job.setPrintable(new PrintDemo1());

    job.setCopies(2);
    job.setJobName("Printable");

    if (job.printDialog()) {
        try {//w  w w.j  a v a 2s .  co m
            job.print();
        } catch (PrinterException e) {
            System.out.println(e);
        }
    }

    System.exit(0);
}

From source file:org.fhaes.fhfilechecker.FrameViewHelp.java

public void btnPrint_actionPerformed(ActionEvent e) {
    // Get a PrinterJob
    PrinterJob job = PrinterJob.getPrinterJob();
    // Ask user for page format (e.g., portrait/landscape)
    PageFormat pf = job.pageDialog(job.defaultPage());
    // Specify the Printable is an instance of
    // PrintListingPainter; also provide given PageFormat
    job.setPrintable(new PrintListingPainter(out_file_name), pf);
    // Print 1 copy
    job.setCopies(1);
    // Put up the dialog box
    if (job.printDialog()) {
        // Print the job if the user didn't cancel printing
        try {/* w  w  w. jav  a  2 s.co m*/
            job.print();
        } catch (Exception ex) {
            /* handle exception */}
    }
}

From source file:org.fhaes.fhfilechecker.FrameViewOutput.java

public void btnPrint_actionPerformed(ActionEvent e) {

    // Get a PrinterJob
    PrinterJob job = PrinterJob.getPrinterJob();
    // Ask user for page format (e.g., portrait/landscape)
    PageFormat pf = job.pageDialog(job.defaultPage());
    // Specify the Printable is an instance of
    // PrintListingPainter; also provide given PageFormat
    job.setPrintable(new PrintListingPainter(out_file_name), pf);
    // Print 1 copy
    job.setCopies(1);
    // Put up the dialog box
    if (job.printDialog()) {
        // Print the job if the user didn't cancel printing
        try {/*from  w w  w.  j  a v  a 2s . c o  m*/
            job.print();
        } catch (Exception ex) {
            /* handle exception */}
    }
}

From source file:org.pentaho.reporting.engine.classic.core.modules.gui.print.PrintUtil.java

public static void printDirectly(final MasterReport report, final ReportProgressListener progressListener)
        throws PrinterException, ReportProcessingException {
    final ModifiableConfiguration reportConfiguration = report.getReportConfiguration();
    final String jobName = reportConfiguration.getConfigProperty(PRINTER_JOB_NAME_KEY, report.getTitle());

    final PrinterJob printerJob = PrinterJob.getPrinterJob();
    if (jobName != null) {
        printerJob.setJobName(jobName);/* w  ww .  j  a  v  a  2  s .com*/
    }

    final PrintReportProcessor reportPane = new PrintReportProcessor(report);
    if (progressListener != null) {
        reportPane.addReportProgressListener(progressListener);
    }
    printerJob.setPageable(reportPane);
    try {
        printerJob.setCopies(getNumberOfCopies(reportConfiguration));
        printerJob.print();
    } finally {
        reportPane.close();
        if (progressListener != null) {
            reportPane.removeReportProgressListener(progressListener);
        }
    }
}

From source file:org.pentaho.reporting.engine.classic.core.modules.gui.print.PrintUtil.java

public static boolean print(final MasterReport report, final ReportProgressListener progressListener)
        throws PrinterException, ReportProcessingException {
    final ModifiableConfiguration reportConfiguration = report.getReportConfiguration();
    final String jobName = reportConfiguration.getConfigProperty(PRINTER_JOB_NAME_KEY, report.getTitle());

    final PrinterJob printerJob = PrinterJob.getPrinterJob();
    if (jobName != null) {
        printerJob.setJobName(jobName);// ww w  .  ja v a 2s.  c o m
    }

    final PrintReportProcessor reportPane = new PrintReportProcessor(report);
    if (progressListener != null) {
        reportPane.addReportProgressListener(progressListener);
    }

    try {
        reportPane.fireProcessingStarted();
        printerJob.setPageable(reportPane);
        printerJob.setCopies(getNumberOfCopies(reportConfiguration));
        if (printerJob.printDialog()) {
            printerJob.print();
            return true;
        }
        return false;
    } finally {
        reportPane.fireProcessingFinished();
        reportPane.close();
        if (progressListener != null) {
            reportPane.removeReportProgressListener(progressListener);
        }
    }
}