Package java.awt.print

Examples of java.awt.print.PrinterException


    private void print(PrinterJob job, boolean silent) throws PrinterException
    {
        if (job == null)
        {
            throw new PrinterException("The given printer job is null.");
        }
        else
        {
            job.setPageable(new PDPageable(this, job));
            if (silent || job.printDialog())
View Full Code Here


   */
  public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException
  {
    if (Thread.currentThread().isInterrupted())
    {
      throw new PrinterException("Current thread interrupted.");
    }

    pageIndex += pageOffset;

    if ( pageIndex < 0 || pageIndex >= jasperPrint.getPages().size() )
    {
      return Printable.NO_SUCH_PAGE;
    }

    try
    {
      JRGraphics2DExporter exporter = new JRGraphics2DExporter();
      exporter.setParameter(JRExporterParameter.JASPER_PRINT, this.jasperPrint);
      exporter.setParameter(JRGraphics2DExporterParameter.GRAPHICS_2D, graphics);
      exporter.setParameter(JRExporterParameter.PAGE_INDEX, new Integer(pageIndex));
      exporter.exportReport();
    }
    catch (JRException e)
    {
      e.printStackTrace();
      throw new PrinterException(e.getMessage());
    }

    return Printable.PAGE_EXISTS;
  }
View Full Code Here

    private void print(PrinterJob job, boolean silent) throws PrinterException
    {
        if (job == null)
        {
            throw new PrinterException("The given printer job is null.");
        }
        else
        {
            job.setPageable(new PDPageable(this, job));
            if (silent || job.printDialog())
View Full Code Here

    private void print(PrinterJob job, boolean silent) throws PrinterException
    {
        if (job == null)
        {
            throw new PrinterException("The given printer job is null.");
        }
        else
        {
            job.setPageable(new PDPageable(this, job));
            if (silent || job.printDialog())
View Full Code Here

     * 2D printing or no longer available.
     */
    public void setPrintService(PrintService service)
        throws PrinterException {
        if (service == null) {
            throw new PrinterException("Service cannot be null");
        } else if (!(service instanceof StreamPrintService) &&
                   service.getName() == null) {
            throw new PrinterException("Null PrintService name.");
        } else {
            // Check the list of services.  This service may have been
            // deleted already
            PrinterState prnState = (PrinterState)service.getAttribute(
                                                  PrinterState.class);
            if (prnState == PrinterState.STOPPED) {
                PrinterStateReasons prnStateReasons =
                    (PrinterStateReasons)service.getAttribute(
                                                 PrinterStateReasons.class);
                if ((prnStateReasons != null) &&
                    (prnStateReasons.containsKey(PrinterStateReason.SHUTDOWN)))
                {
                    throw new PrinterException("PrintService is no longer available.");
                }
            }


            if (service.isDocFlavorSupported(
                                             DocFlavor.SERVICE_FORMATTED.PAGEABLE) &&
                service.isDocFlavorSupported(
                                             DocFlavor.SERVICE_FORMATTED.PRINTABLE)) {
                myService = service;
            } else {
                throw new PrinterException("Not a 2D print service: " + service);
            }
        }
    }
View Full Code Here

           AttributeSet unsupported =
               service.getUnsupportedAttributes(
                                         DocFlavor.SERVICE_FORMATTED.PAGEABLE,
                                         attributes);
           if (unsupported != null) {
               throw new PrinterException("Fidelity cannot be satisfied");
           }
        }

        /*
         * Since we have verified supported values if fidelity is true,
View Full Code Here

         * (and this class).
         */
        PrintService psvc = getPrintService();
        debug_println("psvc = "+psvc);
        if (psvc == null) {
            throw new PrinterException("No print service found.");
        }

        // Check the list of services.  This service may have been
        // deleted already
        PrinterState prnState = (PrinterState)psvc.getAttribute(
                                                  PrinterState.class);
        if (prnState == PrinterState.STOPPED) {
            PrinterStateReasons prnStateReasons =
                    (PrinterStateReasons)psvc.getAttribute(
                                                 PrinterStateReasons.class);
                if ((prnStateReasons != null) &&
                    (prnStateReasons.containsKey(PrinterStateReason.SHUTDOWN)))
                {
                    throw new PrinterException("PrintService is no longer available.");
                }
        }

        if ((PrinterIsAcceptingJobs)(psvc.getAttribute(
                         PrinterIsAcceptingJobs.class)) ==
                         PrinterIsAcceptingJobs.NOT_ACCEPTING_JOBS) {
            throw new PrinterException("Printer is not accepting job.");
        }

        if ((psvc instanceof SunPrinterJobService) &&
            ((SunPrinterJobService)psvc).usesClass(getClass())) {
            setAttributes(attributes);
            // throw exception for invalid destination
            if (destinationAttr != null) {
                // destinationAttr is null for Destination(new URI(""))
                // because isAttributeValueSupported returns false in setAttributes

                // Destination(new URI(" ")) throws URISyntaxException
                File f = new File(destinationAttr);
                try {
                    // check if this is a new file and if filename chars are valid
                    if (f.createNewFile()) {
                        f.delete();
                    }
                } catch (IOException ioe) {
                    throw new PrinterException("Cannot write to file:"+
                                               destinationAttr);
                } catch (SecurityException se) {
                    //There is already file read/write access so at this point
                    // only delete access is denied.  Just ignore it because in
                    // most cases the file created in createNewFile gets overwritten
                    // anyway.
                }

                File pFile = f.getParentFile();
                if ((f.exists() &&
                     (!f.isFile() || !f.canWrite())) ||
                    ((pFile != null) &&
                     (!pFile.exists() || (pFile.exists() && !pFile.canWrite())))) {
                    throw new PrinterException("Cannot write to file:"+
                                               destinationAttr);
                }
            }
        } else {
            spoolToService(psvc, attributes);
View Full Code Here

        try {
            origPage = document.getPageFormat(pageIndex);
            page = (PageFormat)origPage.clone();
            painter = document.getPrintable(pageIndex);
        } catch (Exception e) {
            PrinterException pe =
                    new PrinterException("Error getting page or printable.[ " +
                                          e +" ]");
            pe.initCause(e);
            throw pe;
        }

        /* Get the imageable area from Paper instead of PageFormat
         * because we do not want it adjusted by the page orientation.
         */
        Paper paper = page.getPaper();
        // if non-portrait and 270 degree landscape rotation
        if (page.getOrientation() != PageFormat.PORTRAIT &&
            landscapeRotates270) {

            double left = paper.getImageableX();
            double top = paper.getImageableY();
            double width = paper.getImageableWidth();
            double height = paper.getImageableHeight();
            paper.setImageableArea(paper.getWidth()-left-width,
                                   paper.getHeight()-top-height,
                                   width, height);
            page.setPaper(paper);
            if (page.getOrientation() == PageFormat.LANDSCAPE) {
                page.setOrientation(PageFormat.REVERSE_LANDSCAPE);
            } else {
                page.setOrientation(PageFormat.LANDSCAPE);
            }
        }

        double xScale = getXRes() / 72.0;
        double yScale = getYRes() / 72.0;

        /* The deviceArea is the imageable area in the printer's
         * resolution.
         */
        Rectangle2D deviceArea =
            new Rectangle2D.Double(paper.getImageableX() * xScale,
                                   paper.getImageableY() * yScale,
                                   paper.getImageableWidth() * xScale,
                                   paper.getImageableHeight() * yScale);

        /* Build and hold on to a uniform transform so that
         * we can get back to device space at the beginning
         * of each band.
         */
        AffineTransform uniformTransform = new AffineTransform();

        /* The scale transform is used to switch from the
         * device space to the user's 72 dpi space.
         */
        AffineTransform scaleTransform = new AffineTransform();
        scaleTransform.scale(xScale, yScale);

        /* bandwidth is multiple of 4 as the data is used in a win32 DIB and
         * some drivers behave badly if scanlines aren't multiples of 4 bytes.
         */
        int bandWidth = (int) deviceArea.getWidth();
        if (bandWidth % 4 != 0) {
            bandWidth += (4 - (bandWidth % 4));
        }
        if (bandWidth <= 0) {
            throw new PrinterException("Paper's imageable width is too small.");
        }

        int deviceAreaHeight = (int)deviceArea.getHeight();
        if (deviceAreaHeight <= 0) {
            throw new PrinterException("Paper's imageable height is too small.");
        }

        /* Figure out the number of lines that will fit into
         * our maximum band size. The hard coded 3 reflects the
         * fact that we can only create 24 bit per pixel 3 byte BGR
View Full Code Here

        if (epsPrinter == null) {
            if (getPrintService() instanceof PSStreamPrintService) {
                StreamPrintService sps = (StreamPrintService)getPrintService();
                mDestType = RasterPrinterJob.STREAM;
                if (sps.isDisposed()) {
                    throw new PrinterException("service is disposed");
                }
                output = sps.getOutputStream();
                if (output == null) {
                    throw new PrinterException("Null output stream");
                }
            } else {
                /* REMIND: This needs to be more maintainable */
                mNoJobSheet = super.noJobSheet;
                if (super.destinationAttr != null) {
View Full Code Here

                    page = psDocument.getPrintable(iPage);
                    pageFormat = psDocument.getPageFormat(iPage);
                    if (page != null) {
                        result = page.print(fake, pageFormat, iPage);
                    } else {
                        throw new PrinterException("No printable for page " +
                                iPage + " in given document.");
                    }
                }
                if (result == Printable.PAGE_EXISTS) {
                    converter.startPage(iPage + 1);
View Full Code Here

TOP

Related Classes of java.awt.print.PrinterException

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.