Package net.sf.jasperreports.engine.export

Examples of net.sf.jasperreports.engine.export.JRPrintServiceExporter


    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.setParameter(JRExporterParameter.INPUT_FILE_NAME, "build/reports/PrintServiceReport.jrprint");
    exporter.setParameter(JRPrintServiceExporterParameter.PRINT_REQUEST_ATTRIBUTE_SET, printRequestAttributeSet);
    exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE_ATTRIBUTE_SET, printServiceAttributeSet);
    exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG, Boolean.FALSE);
    exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, Boolean.TRUE);
   
    exporter.exportReport();

    System.err.println("Printing time : " + (System.currentTimeMillis() - start));
  }
View Full Code Here


    JRResultSetDataSource jasperresultset;
    JasperPrint jasperPrint = new JasperPrint();
    Connection connection;
    JInternalFrameReportViewer reportviewer;
    Icon reportIcon;
    JRPrintServiceExporter exporter;
    // PrintServiceAttributeSet serviceAttributeSet;
    String reportFilename = "";

    mod.setModuleId(moduleId);

    if (mod.getModuleProperties() == true)
    {
      reportFilename = Common.report_path + JUtility.removeExtensionFromFilename(mod.getReportFilename(), ".jrxml") + ".jasper";

      if (parameterValues == null)
      {
        parameterValues = new HashMap<String, Object>();
      }
      parameterValues.putAll(stdparams);

      printQueue = JUtility.replaceNullStringwithBlank(printQueue);

      if (printQueue.equals(""))
      {
        printQueue = JPrint.getDefaultPrinterQueueName();
      } else
      {
        if (JPrint.getDefaultPrinterQueueName().equals(printQueue) == false)
        {
          JPrint.setPreferredPrinterQueueName(printQueue);
        }
      }

      try
      {

        connection = Common.hostList.getHost(Common.selectedHostID).getConnection(Common.sessionID);

        sql = JUtility.replaceNullStringwithBlank(sql);

        if (sql.isEmpty())
        {
          if (preparedstatement == null)
          {
            parameterValues.put(JRParameter.REPORT_CONNECTION, connection);
            jasperPrint = JasperFillManager.fillReport(reportFilename, parameterValues, connection);
          } else
          {
            resultset = preparedstatement.executeQuery();
            jasperresultset = new JRResultSetDataSource(resultset);
            parameterValues.put(JRParameter.REPORT_DATA_SOURCE, jasperresultset);
            parameterValues.put(JRParameter.REPORT_CONNECTION, connection);
            jasperPrint = JasperFillManager.fillReport(reportFilename, parameterValues, jasperresultset);
          }
        } else
        {
          statement = Common.hostList.getHost(Common.selectedHostID).getConnection(Common.sessionID).createStatement();
          statement.setFetchSize(1);
          resultset = statement.executeQuery(sql);
          jasperresultset = new JRResultSetDataSource(resultset);
          parameterValues.put(JRParameter.REPORT_DATA_SOURCE, jasperresultset);
          parameterValues.put(JRParameter.REPORT_CONNECTION, connection);
          jasperPrint = JasperFillManager.fillReport(reportFilename, parameterValues, jasperresultset);
        }

        if (mod.isPrintPreview() == true)
        {
          reportviewer = new JInternalFrameReportViewer(jasperPrint, false);
          reportIcon = Common.imageIconloader.getImageIcon(Common.image_report);
          reportviewer.setFrameIcon(reportIcon);
          reportviewer.setLocation(JLaunchMenu.getNextWindowPosition().x, JLaunchMenu.getNextWindowPosition().y);
          Common.mainForm.desktopPane.add(reportviewer);
          reportviewer.setVisible(true);
          reportviewer.setSelected(true);

        } else
        {

          exporter = new JRPrintServiceExporter();
          exporter.setExporterInput(new SimpleExporterInput(jasperPrint));

          PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();
          printRequestAttributeSet.add(new Copies(mod.getPrintCopies()));


          PrintServiceAttributeSet printServiceAttributeSet = new HashPrintServiceAttributeSet();
          printServiceAttributeSet.add(new PrinterName(JPrint.getPrinterServicebyName(printQueue).getName(), Locale.getDefault()));

          SimplePrintServiceExporterConfiguration configuration = new SimplePrintServiceExporterConfiguration();
          configuration.setPrintRequestAttributeSet(printRequestAttributeSet);
          configuration.setPrintServiceAttributeSet(printServiceAttributeSet);
          configuration.setDisplayPageDialog(false);
          configuration.setDisplayPrintDialog(mod.isPrintDialog());

          exporter.setConfiguration(configuration);
          exporter.exportReport();

        }

      } catch (Exception e)
      {
View Full Code Here

    JRResultSetDataSource jasperresultset;
    JasperPrint jasperPrint = new JasperPrint();
    Connection connection;
    JInternalFrameReportViewer reportviewer;
    Icon reportIcon;
    JRPrintServiceExporter exporter;
    PrintServiceAttributeSet serviceAttributeSet;
    String reportFilename = "";
   
    mod.setModuleId(moduleId);

    if (mod.getModuleProperties() == true)
    {
      reportFilename = Common.report_path  + JUtility.removeExtensionFromFilename(mod.getReportFilename(), ".jrxml") + ".jasper";
     
      if (parameterValues==null)
      {
        parameterValues = new HashMap<String, Object>();
      }
      parameterValues.putAll(stdparams);

      printQueue = JUtility.replaceNullStringwithBlank(printQueue);
     
      if (printQueue.equals(""))
      {
        printQueue = JPrint.getDefaultPrinterQueueName();
      }
      else
      {
        if (JPrint.getDefaultPrinterQueueName().equals(printQueue) == false)
        {
          JPrint.setPreferredPrinterQueueName(printQueue);
        }
      }

      try
      {
        //jasperReport = (JasperReport) JRLoader.loadObjectFromLocation(Common.report_path + JUtility.removeExtensionFromFilename(mod.getReportFilename(), ".jrxml")+ ".jasper");
        //jasperReport = (JasperReport) RepositoryUtil.getReport(Common.report_path + JUtility.removeExtensionFromFilename(mod.getReportFilename(), ".jrxml")+ ".jasper");
        connection = Common.hostList.getHost(Common.selectedHostID).getConnection(Common.sessionID);

        sql = JUtility.replaceNullStringwithBlank(sql);

        if (sql.isEmpty())
        {
          if (preparedstatement==null)
          {
            parameterValues.put(JRParameter.REPORT_CONNECTION, connection);
            jasperPrint = JasperFillManager.fillReport(reportFilename, parameterValues, connection);
          }
          else
          {
            resultset = preparedstatement.executeQuery();
            jasperresultset = new JRResultSetDataSource(resultset);
            parameterValues.put(JRParameter.REPORT_DATA_SOURCE, jasperresultset);
            parameterValues.put(JRParameter.REPORT_CONNECTION, connection);
            jasperPrint = JasperFillManager.fillReport(reportFilename, parameterValues, jasperresultset);
          }
        }
        else
        {
          statement = Common.hostList.getHost(Common.selectedHostID).getConnection(Common.sessionID).createStatement();
          statement.setFetchSize(1);
          resultset = statement.executeQuery(sql);
          jasperresultset = new JRResultSetDataSource(resultset);
          parameterValues.put(JRParameter.REPORT_DATA_SOURCE, jasperresultset);
          parameterValues.put(JRParameter.REPORT_CONNECTION, connection);
          jasperPrint = JasperFillManager.fillReport(reportFilename, parameterValues, jasperresultset);
        }

        if (mod.isPrintPreview() == true)
        {
          reportviewer = new JInternalFrameReportViewer(jasperPrint, false);
          reportIcon = Common.imageIconloader.getImageIcon(Common.image_report);
          reportviewer.setFrameIcon(reportIcon);
          reportviewer.setLocation(JLaunchMenu.getNextWindowPosition().x, JLaunchMenu.getNextWindowPosition().y);
          Common.mainForm.desktopPane.add(reportviewer);
          reportviewer.setVisible(true);
          reportviewer.setSelected(true);

        }
        else
        {
          exporter = new JRPrintServiceExporter();
          exporter.setParameter(JRPrintServiceExporterParameter.JASPER_PRINT, jasperPrint);
          serviceAttributeSet = new HashPrintServiceAttributeSet();
          serviceAttributeSet.add(new PrinterName(JPrint.getPrinterShortName(JPrint.getPreferredPrinterQueueName()), null));
          exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE_ATTRIBUTE_SET, serviceAttributeSet);
          exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG, Boolean.FALSE);
          exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, mod.isPrintDialog());
          PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();
          printRequestAttributeSet.add(new Copies(mod.getPrintCopies()));
          exporter.setParameter(JRPrintServiceExporterParameter.PRINT_REQUEST_ATTRIBUTE_SET, printRequestAttributeSet);
          exporter.exportReport();
         
          /* Alternative method
            exporter = new JRPrintServiceExporter();
         
              PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();
View Full Code Here

TOP

Related Classes of net.sf.jasperreports.engine.export.JRPrintServiceExporter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.