Java 类net.sf.jasperreports.engine.export.JRPrintServiceExporter 实例源码

项目:jasperreports    文件:PrintServiceApp.java   
/**
 *
 */
public void print() throws JRException
{
    long start = System.currentTimeMillis();
    PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();
    printRequestAttributeSet.add(MediaSizeName.ISO_A4);

    PrintServiceAttributeSet printServiceAttributeSet = new HashPrintServiceAttributeSet();
    //printServiceAttributeSet.add(new PrinterName("Epson Stylus 820 ESC/P 2", null));
    //printServiceAttributeSet.add(new PrinterName("hp LaserJet 1320 PCL 6", null));
    //printServiceAttributeSet.add(new PrinterName("PDFCreator", null));

    JRPrintServiceExporter exporter = new JRPrintServiceExporter();

    exporter.setExporterInput(new SimpleExporterInput("build/reports/PrintServiceReport.jrprint"));
    SimplePrintServiceExporterConfiguration configuration = new SimplePrintServiceExporterConfiguration();
    configuration.setPrintRequestAttributeSet(printRequestAttributeSet);
    configuration.setPrintServiceAttributeSet(printServiceAttributeSet);
    configuration.setDisplayPageDialog(false);
    configuration.setDisplayPrintDialog(true);
    exporter.setConfiguration(configuration);
    exporter.exportReport();

    System.err.println("Printing time : " + (System.currentTimeMillis() - start));
}
项目:jasperreports    文件:JasperPrintManager.java   
/**
 *
 */
public boolean print(
    JasperPrint jasperPrint,
    boolean withPrintDialog
    ) throws JRException
{
    //artf1936
    boolean checkAvailablePrinters = JRPropertiesUtil.getInstance(jasperReportsContext).getBooleanProperty(jasperPrint, PROPERTY_CHECK_AVAILABLE_PRINTERS, true);
    if (checkAvailablePrinters && !(unixSunJDK || JRPrintServiceExporter.checkAvailablePrinters())) 
    {
        throw 
            new JRException(
                EXCEPTION_MESSAGE_KEY_NO_AVAILABLE_PRINTER,
                (Object[])null);
    }
    //END - artf1936

    return 
        print(
            jasperPrint,
            0,
            jasperPrint.getPages().size() - 1,
            withPrintDialog
            );
}
项目:zprojects    文件:JExportarReporte.java   
@Override protected Object doInBackground() {
    try {
        // Your Task's code here.  This method runs
        // on a background thread, so don't reference
        // the Swing GUI from here.
        PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();
        printRequestAttributeSet.add(MediaSizeName.ISO_A4);

        PrintServiceAttributeSet printServiceAttributeSet = new HashPrintServiceAttributeSet();
        //printServiceAttributeSet.add(new PrinterName("Epson Stylus 820 ESC/P 2", null));
        //printServiceAttributeSet.add(new PrinterName("hp LaserJet 1320 PCL 6", null));
        //printServiceAttributeSet.add(new PrinterName("PDFCreator", null));

        JRPrintServiceExporter exporter = new JRPrintServiceExporter();

        exporter.setExporterInput(new SimpleExporterInput(report));
        SimplePrintServiceExporterConfiguration configuration = new SimplePrintServiceExporterConfiguration();
        configuration.setPrintRequestAttributeSet(printRequestAttributeSet);
        configuration.setPrintServiceAttributeSet(printServiceAttributeSet);
        configuration.setDisplayPageDialog(false);
        configuration.setDisplayPrintDialog(true);
        exporter.setConfiguration(configuration);
        exporter.exportReport();

    } catch (JRException ex) {
        Logger.getLogger(JExportarReporte.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;  // return your result
}
项目: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()));
    }
    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();
}