Package java.awt.print

Examples of java.awt.print.PrinterJob


    /**
     * Can be called directly
     * @throws PrinterException
     */
    public void print() throws PrinterException {
        PrinterJob job = PrinterJob.getPrinterJob();
        //PageFormat pf = job.defaultPage();
        //pf.setOrientation(orientation.get());
        job.setPrintService(ps.get());
        job.setPrintable(this);
        job.setJobName(jobName.get());
        job.print();
    }
View Full Code Here


         if (_table != null)
         {
            try
            {

               PrinterJob printerJob = PrinterJob.getPrinterJob();

               printerJob.setPrintable(_viewer);

               if (printerJob.printDialog())
               {
                  printerJob.print();
               }
            }
            catch (Exception e)
            {
               throw new RuntimeException(e);
View Full Code Here

      if (displayPrintDialog && printDialogOnlyOnce != null)
      {
//         it can be (eventually) set to true only if displayPrintDialog is true
        displayPrintDialogOnlyOnce = printDialogOnlyOnce.booleanValue();
      }
      PrinterJob printerJob = PrinterJob.getPrinterJob();
     
      JRPrinterAWT.initPrinterJobFields(printerJob);
     
      printerJob.setPrintable(this);
     
      printStatus = null;
     
      // determining the print service only once
      printService = (PrintService) parameters.get(JRPrintServiceExporterParameter.PRINT_SERVICE);
      if (printService == null) {
        PrintService[] services = PrintServiceLookup.lookupPrintServices(null, printServiceAttributeSet);
        if (services.length > 0)
        {
          printService = services[0];
        }
      }
     
      if (printService == null)
      {
        throw new JRException("No suitable print service found.");
      }

      try
      {
        printerJob.setPrintService(printService);
      }
      catch (PrinterException e)
      {
        throw new JRException(e);
      }

      PrintRequestAttributeSet printRequestAttributeSet = null;
      if(displayPrintDialogOnlyOnce || displayPageDialogOnlyOnce)
      {
        printRequestAttributeSet = new HashPrintRequestAttributeSet();
        setDefaultPrintRequestAttributeSet(printRequestAttributeSet);
        setOrientation((JasperPrint)jasperPrintList.get(0), printRequestAttributeSet);
        if(displayPageDialogOnlyOnce)
        {
          if(printerJob.pageDialog(printRequestAttributeSet) == null)
          {
            return;
          }
          else
          {
            displayPageDialog = false;
          }
        }
        if(displayPrintDialogOnlyOnce)
        {
          if(!printerJob.printDialog(printRequestAttributeSet))
          {
            printStatus = new Boolean[]{Boolean.FALSE};
            return;
          }
          else
          {
            displayPrintDialog = false;
          }
        }
      }
     
      List status = new ArrayList();
      // fix for bug ID artf1455 from jasperforge.org bug database
      for(reportIndex = 0; reportIndex < jasperPrintList.size(); reportIndex++)
      {
        setJasperPrint((JasperPrint)jasperPrintList.get(reportIndex));

        exporter = new JRGraphics2DExporter();
        exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
        exporter.setParameter(JRExporterParameter.PROGRESS_MONITOR, parameters.get(JRExporterParameter.PROGRESS_MONITOR));
        exporter.setParameter(JRExporterParameter.OFFSET_X, parameters.get(JRExporterParameter.OFFSET_X));
        exporter.setParameter(JRExporterParameter.OFFSET_Y, parameters.get(JRExporterParameter.OFFSET_Y));
        exporter.setParameter(JRGraphics2DExporterParameter.ZOOM_RATIO, parameters.get(JRGraphics2DExporterParameter.ZOOM_RATIO));
        exporter.setParameter(JRExporterParameter.CLASS_LOADER, classLoader);
        exporter.setParameter(JRExporterParameter.URL_HANDLER_FACTORY, urlHandlerFactory);
        exporter.setParameter(JRExporterParameter.FILE_RESOLVER, fileResolver);
        if (parameters.containsKey(JRExporterParameter.FILTER))
        {
          exporter.setParameter(JRExporterParameter.FILTER, filter);
        }
        exporter.setParameter(JRGraphics2DExporterParameter.MINIMIZE_PRINTER_JOB_SIZE, parameters.get(JRGraphics2DExporterParameter.MINIMIZE_PRINTER_JOB_SIZE));
       
        if(displayPrintDialog || displayPageDialog ||
            (!displayPrintDialogOnlyOnce && !displayPageDialogOnlyOnce))
        {
          printRequestAttributeSet = new HashPrintRequestAttributeSet();
          setDefaultPrintRequestAttributeSet(printRequestAttributeSet);
          setOrientation(jasperPrint, printRequestAttributeSet);
        }
   
        try
        {
         
          if (!isModeBatch)
          {
            printRequestAttributeSet.add(new PageRanges(startPageIndex + 1, endPageIndex + 1));
          }

          printerJob.setJobName("JasperReports - " + jasperPrint.getName());

          if (displayPageDialog)
          {
            printerJob.pageDialog(printRequestAttributeSet);
          }
          if (displayPrintDialog)
          {
            if (printerJob.printDialog(printRequestAttributeSet))
            {
              status.add(Boolean.TRUE);
              printerJob.print(printRequestAttributeSet);
            }
            else
            {
              status.add(Boolean.FALSE);
            }
          }
          else
          {
            PageFormat pageFormat = printerJob.defaultPage();
            Paper paper = pageFormat.getPaper();
           
            switch (jasperPrint.getOrientationValue())
            {
              case LANDSCAPE :
              {
                pageFormat.setOrientation(PageFormat.LANDSCAPE);
                paper.setSize(jasperPrint.getPageHeight(), jasperPrint.getPageWidth());
                paper.setImageableArea(
                  0,
                  0,
                  jasperPrint.getPageHeight(),
                  jasperPrint.getPageWidth()
                  );
                break;
              }
              case PORTRAIT :
              default :
              {
                pageFormat.setOrientation(PageFormat.PORTRAIT);
                paper.setSize(jasperPrint.getPageWidth(), jasperPrint.getPageHeight());
                paper.setImageableArea(
                  0,
                  0,
                  jasperPrint.getPageWidth(),
                  jasperPrint.getPageHeight()
                  );
              }
            }
           
            // setting the paper object back as getPaper() returns a clone
            pageFormat.setPaper(paper);
           
            printerJob.setPrintable(this, pageFormat);

            printerJob.print(printRequestAttributeSet);
          }
        }
        catch (PrinterException e)
        {
          throw new JRException(e);
        }
      }
     
      printStatus = (Boolean[]) status.toArray(new Boolean[status.size()]);
      printService = printerJob.getPrintService();
    }
    finally
    {
      resetExportContext();
    }
View Full Code Here

public class PrintManager {

    public static void printChart(Chart chart, GanttExportSettings settings) {
        BufferedImage image = chart.getChart(settings);

        PrinterJob printJob = PrinterJob.getPrinterJob();

        printJob.setPrintable(new GanttPrintable(image,
                GanttPrintable.REDUCE_FACTOR_DEFAULT));

        PrintRequestAttributeSet attr = new HashPrintRequestAttributeSet();
        attr.add(MediaSizeName.ISO_A4);
        attr.add(OrientationRequested.LANDSCAPE);

        if (printJob.printDialog(attr)) {
            try {
                printJob.print(attr);
            } catch (Exception e) {
              if (!GPLogger.log(e)) {
                e.printStackTrace(System.err);
              }
            }
View Full Code Here

        statusBar.setLabel1(language.getText("paperSize"));
        getContentPane().add(statusBar, BorderLayout.SOUTH);

        myPreviewContainer = new PreviewContainer();

        PrinterJob prnJob = PrinterJob.getPrinterJob();

        // --
        myPageFormat = new PageFormat();
        myPageFormat.setOrientation(myOrientation);
View Full Code Here

        myPreviewContainer.validate();

    }

    private void print() {
        PrinterJob prnJob = PrinterJob.getPrinterJob();
        prnJob.setPrintable(myPrintable);
        setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

        PrintRequestAttributeSet attr = new HashPrintRequestAttributeSet();
        attr.add(myMediaSizeName);
        attr.add(myOrientation == PageFormat.LANDSCAPE ?
               OrientationRequested.LANDSCAPE :
                   OrientationRequested.PORTRAIT);
        Document doc = myProject.getDocument();
        if (doc != null)
            attr.add(new JobName(doc.getDescription(), language.getLocale()));

        if (prnJob.printDialog(attr)) {
            try {
                prnJob.print(attr);
                setVisible(false);

            } catch (Exception e) {
              e.printStackTrace();
              myUIfacade.showErrorDialog(e);
View Full Code Here

  public boolean print(
    Pageable document,
    boolean silent
    ) throws PrinterException
  {
    PrinterJob printJob = PrinterJob.getPrinterJob();
    printJob.setPageable(document);
    if(!(silent || printJob.printDialog()))
      return false;

    printJob.print();
    return true;
  }
View Full Code Here

  /**
   * Returns a <code>PageFormat</code> object created from <code>homePrint</code>.
   */
  public static PageFormat getPageFormat(HomePrint homePrint) {
    final PrinterJob printerJob = PrinterJob.getPrinterJob();
    if (homePrint == null) {
      return printerJob.defaultPage();
    } else {
      PageFormat pageFormat = new PageFormat();
      switch (homePrint.getPaperOrientation()) {
        case PORTRAIT :
          pageFormat.setOrientation(PageFormat.PORTRAIT);
          break;
        case LANDSCAPE :
          pageFormat.setOrientation(PageFormat.LANDSCAPE);
          break;
        case REVERSE_LANDSCAPE :
          pageFormat.setOrientation(PageFormat.REVERSE_LANDSCAPE);
          break;
      }
      Paper paper = new Paper();
      paper.setSize(homePrint.getPaperWidth(), homePrint.getPaperHeight());
      paper.setImageableArea(homePrint.getPaperLeftMargin(), homePrint.getPaperTopMargin(),
          homePrint.getPaperWidth() - homePrint.getPaperLeftMargin() - homePrint.getPaperRightMargin(),
          homePrint.getPaperHeight() - homePrint.getPaperTopMargin() - homePrint.getPaperBottomMargin());
      pageFormat.setPaper(paper);
      pageFormat = printerJob.validatePage(pageFormat);
      return pageFormat;
    }
  }
View Full Code Here

   *    or an {@link InterruptedRecorderException InterruptedRecorderException}
   *    exception if it was interrupted.
   */
  public Callable<Void> showPrintDialog() {
    PageFormat pageFormat = HomePrintableComponent.getPageFormat(this.home.getPrint());
    final PrinterJob printerJob = PrinterJob.getPrinterJob();
    printerJob.setPrintable(new HomePrintableComponent(this.home, this.controller, getFont()), pageFormat);
    String jobName = this.preferences.getLocalizedString(HomePane.class, "print.jobName");
    if (this.home.getName() != null) {
      jobName += " - " + this.controller.getContentManager().getPresentationName(
          this.home.getName(), ContentManager.ContentType.SWEET_HOME_3D);
    }
    printerJob.setJobName(jobName);
    if (printerJob.printDialog()) {
      return new Callable<Void>() {
          public Void call() throws RecorderException {
            try {
              printerJob.print();
              return null;
            } catch (InterruptedPrinterException ex) {
              throw new InterruptedRecorderException("Print interrupted");
            } catch (PrinterException ex) {
              throw new RecorderException("Couldn't print", ex);
View Full Code Here

      }
    };
    this.pageFormatButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
          // Show the page setup dialog
          PrinterJob printerJob = PrinterJob.getPrinterJob();
          pageFormat = printerJob.pageDialog(pageFormat);
          updateController(controller);
        }
      });
    ItemListener itemListener = new ItemListener() {
        public void itemStateChanged(ItemEvent ev) {
View Full Code Here

TOP

Related Classes of java.awt.print.PrinterJob

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.