Example usage for java.awt.print PrinterJob getPrintService

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

Introduction

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

Prototype

public PrintService getPrintService() 

Source Link

Document

Returns the service (printer) for this printer job.

Usage

From source file:com.openbravo.pos.util.JRPrinterAWT.java

/**
 * Fix for bug ID 6255588 from Sun bug database
 * @param job print job that the fix applies to
 *//*  w  w w  .ja va  2  s .  c o m*/
public static void initPrinterJobFields(PrinterJob job) {
    try {
        job.setPrintService(job.getPrintService());
    } catch (PrinterException e) {
    }
}

From source file:com.aw.core.report.ReportFileGenerator.java

public String generateAndPrint(String reportName, Map params, String tempDirectory, Connection conn)
        throws JRException {
    // force temp directory end with "/"
    //        tempDirectory = formatDirectory(tempDirectory);
    //        String fullOutFileName = generateFile(conn);
    //        String fullPdfFileName = fullOutFileName + ".pdf";
    //        JasperExportManager.exportReportToPdfFile(fullOutFileName, fullPdfFileName);

    //Report loading and compilation
    //        JasperDesign jasperDesign = JRXmlLoader.load(compiledReport);
    //        JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);

    // - Report execution

    //        JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, conn);

    try {/* w ww . j ava 2  s  .  co m*/
        // - Report creation to printer
        PrinterJob job = PrinterJob.getPrinterJob();
        DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE; // This is the Flavour JasperReports uses

        PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
        aset.add(MediaSizeName.ISO_A4); // ..or whatever the document size is

        PrintService service = null;
        if (job.printDialog(aset))
            service = job.getPrintService();

        InputStream jasperReport = new FileInputStream("C:/ProgFile/iReport-2.0.2/CorrelativoDocumento.jasper");
        JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, conn);

        // Export the report using the JasperPrint instance
        JRExporter exporter = new JRPrintServiceExporter();
        exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
        exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE_ATTRIBUTE_SET,
                service.getAttributes());
        exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG, Boolean.FALSE);
        exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, Boolean.FALSE);

        exporter.exportReport();

        //            String fullPdfFileName = "D:\\test.pdf";
        //            JasperExportManager.exportReportToPdfFile(jasperPrint, fullPdfFileName);

        return null;
    } catch (FileNotFoundException e) {
        throw AWBusinessException.wrapUnhandledException(logger, e);
    }

}