Package javax.print

Examples of javax.print.PrintException


            throw e;
        } catch (Exception e) {
            if (getVerbose() > 1) {
                e.printStackTrace();
            }
            throw new PrintException(e);
        }
    }
View Full Code Here


            throws PrintException {
        if (response.getStatusCode() != 0) {
            String status = Integer.toHexString(response.getStatusCode());
            String id = Integer.toHexString(response.getRequestId());

            throw new PrintException(prefix
                    + "\n================ IPP response id: 0x" + id
                    + " =====================" + "\nresponse status code: 0x"
                    + status + "\n" + response.toString()
                    + "\n================ end IPP response 0x" + id
                    + " =====================");
View Full Code Here

    public void print(Doc userDoc, PrintRequestAttributeSet printRequestAS)
            throws PrintException {

        synchronized (this) {
            if (busyFlag) {
                throw new PrintException(
                        "Already printed. Need to create new DocPrintJob.");
            }
            busyFlag = true;
        }
       
        DocFlavor userDocDF = userDoc.getDocFlavor();

        /*
         * Checking if doc.DocFlavor is supported by the current
         * PrintService
         */
        if (!printService.isDocFlavorSupported(userDocDF)) {
            throw new PrintException("Doc flavor \'" + userDocDF
                    + "\' is not supported");
        }

        /*
         * Checking if doc.DocFlavor is supported directly by osClent. If it
         * is not: - get StereamPrintServiceFactory for doc.DocFlavor -
         * instantiate StreamPrintService - get PrintJob from it - run this
         * PrintJob in separate thread
         */
        printClient = printService.getPrintClient();
        if (printService.isDocFlavorSupportedByClient(userDocDF)) {
            printClient.print(userDoc, printRequestAS);
        } else {
            try {
                Doc clientDoc = userDoc;
                PipedOutputStream spsOutStream = new PipedOutputStream();
                PipedInputStream clientInputStream = new PipedInputStream(
                        spsOutStream);

                DocFlavor newFlavor = null;
                StreamPrintServiceFactory spsf = null;
                DocFlavor clientFlavors[] = printClient
                        .getSupportedDocFlavors();

                for (int i = 0; i < clientFlavors.length; i++) {
                    StreamPrintServiceFactory[] factories = StreamPrintServiceFactory
                            .lookupStreamPrintServiceFactories(userDocDF,
                                    clientFlavors[i].getMimeType());
                    if (factories.length > 0
                            && Class.forName(
                                    clientFlavors[i]
                                            .getRepresentationClassName())
                                    .isInstance(clientInputStream)) {
                        spsf = factories[0];
                        newFlavor = clientFlavors[i];
                        break;
                    }
                }

                if (spsf != null) {
                    StreamPrintService sps = spsf.getPrintService(spsOutStream);

                    /*
                     * Constructing new Doc object for client: - connecting
                     * InputStream of client with OutputStream of
                     * StreamPrintSrevice - constructing DocFlavor for
                     * StreamPrintSrevice output - creating new SimpleDoc
                     * for client
                     */
                    clientDoc = new SimpleDoc(clientInputStream, newFlavor,
                            userDoc.getAttributes());

                    PrintJobThread printThread = new PrintJobThread(this,
                            userDoc, printRequestAS, sps);
                    printThread.start();
                    printClient.print(clientDoc, printRequestAS);

                    if (printThread.exceptionOccured()) {
                        throw new PrintException(printThread
                                .getPrintException());
                    }
                } else {
                    throw new PrintException("Doc flavor "
                            + userDocDF.getRepresentationClassName()
                            + " is not supported");
                }
            } catch (ClassNotFoundException e) {
                throw new PrintException(e);
            } catch (IOException e) {
                throw new PrintException(e);
            } catch (PrintException e) {
                throw e;
            }
        }
    }
View Full Code Here

                for (int j = 0; j < bufferLength; j++) {
                    byteImage[k++] = buffer[j];
                }
            }               
        } catch (IOException ioe) {
            throw new PrintException("Can't read print data.");
        }
       
        toolkit = Toolkit.getDefaultToolkit();

        image = toolkit.createImage(byteImage);
        while (!toolkit.prepareImage(image, -1, -1, null) &&
               (toolkit.checkImage(image, -1, -1, null) &
                       (ImageObserver.ERROR | ImageObserver.ABORT)) == 0) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException ie) {
                // Interrupted by user.
                return (BufferedImage) null;
            }
        }
        if (!toolkit.prepareImage(image, -1, -1, null)) {
            throw new PrintException("Error while loading image (possibly, " +
                    "image format is not supported).");
        }
        BufferedImage bufferedImage = new BufferedImage(image.getWidth(null),
                image.getHeight(null), BufferedImage.TYPE_INT_ARGB);
        Graphics graphics = bufferedImage.getGraphics();
View Full Code Here

        float scaleX;
        float scaleY;
       
        synchronized (this) {
            if (action) {
                throw new PrintException("printing is in action");
            }
            action = true;
        }

        try { // for finally block. To make action false.

            docflavor = doc.getDocFlavor();
            try {
                data = doc.getPrintData();
            } catch (IOException ioexception) {
                throw new PrintException("no data for print: "
                        + ioexception.toString());
            }           
            if (docflavor == null) {
                throw new PrintException("flavor is null");
            }
            if (!begetPrintService.isDocFlavorSupported(docflavor)) {
                throw new PrintException("invalid flavor :"
                        + docflavor.toString());
            }

            docflavorClassName = docflavor.getRepresentationClassName();

            if (docflavor.equals(DocFlavor.INPUT_STREAM.GIF) ||
                docflavor.equals(DocFlavor.BYTE_ARRAY.GIF) ||
                docflavor.equals(DocFlavor.INPUT_STREAM.JPEG) ||
                docflavor.equals(DocFlavor.BYTE_ARRAY.JPEG) ||
                docflavor.equals(DocFlavor.INPUT_STREAM.PNG) ||
                docflavor.equals(DocFlavor.BYTE_ARRAY.PNG)) {               
                try {
                    image = readImage(doc.getStreamForBytes());
                } catch (IOException ioe) {
                    throw new PrintException(ioe);
                }
            } else if (docflavor.equals(DocFlavor.URL.GIF) ||
                       docflavor.equals(DocFlavor.URL.JPEG) ||
                       docflavor.equals(DocFlavor.URL.PNG)) {
                URL url = (URL) data;
                try {
                    image = readImage(url.openStream());
                } catch (IOException ioe) {
                    throw new PrintException(ioe);
                }
            } else if (docflavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE)){
                Printable printable = (Printable)data;
                print(printable, null);
            } else if (docflavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE)) {
                Pageable pageable = (Pageable)data;
                print(null, pageable);
            } else {
                throw new PrintException("Wrong DocFlavor class: "
                        + docflavorClassName);
            }

            if (image != null) {
                MediaSize size = null;
View Full Code Here

                    result = page.print(converter, pageFormat, iPage);
                    converter.endOfPage(iPage + 1);
                }
            } catch (PrinterException pe) {
                converter.finish();
                throw new PrintException(pe.getMessage());
            }
            iPage++;           
        } while (result == Printable.PAGE_EXISTS);
        converter.finish();
    }
View Full Code Here

        try {
            this.printeruri = new URI(name);
            this.printer = new IppPrinter(printeruri);
            this.attributeset = new HashPrintServiceAttributeSet();
        } catch (Exception e) {
            throw new PrintException(e);
        }
    }
View Full Code Here

                if (!(df instanceof DocFlavor.INPUT_STREAM
                        || df instanceof DocFlavor.BYTE_ARRAY
                        || df instanceof DocFlavor.CHAR_ARRAY
                        || df instanceof DocFlavor.STRING
                        || df instanceof DocFlavor.READER || df instanceof DocFlavor.URL)) {
                    throw new PrintException("Doc flavor "
                            + df.getRepresentationClassName()
                            + " is not supported yet");
                }

                HashAttributeSet as = new HashAttributeSet();
                DocAttributeSet das;
                das = doc.getAttributes();

                // construct attributes
                if (das != null) {
                    as.addAll(das);
                }
                if (attributes != null) {
                    as.addAll(attributes);
                }
                as.addAll(attributeset);

                // print
                if (as.containsKey(Destination.class)) {
                    print2destination(doc, (Destination) as
                            .get(Destination.class));
                } else {
                    printsimple(doc, as);
                }
            } catch (PrintException e) {
                throw e;
            } catch (Exception e) {
                throw new PrintException(e);
            }
        }
    }
View Full Code Here

            }

            bw.flush();
            bw.close();
        } catch (Exception e) {
            throw new PrintException(e);
        }
    }
View Full Code Here

            throw e;
        } catch (Exception e) {
            if (getVerbose() > 1) {
                e.printStackTrace();
            }
            throw new PrintException(e);
        }
    }
View Full Code Here

TOP

Related Classes of javax.print.PrintException

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.