Package javax.print

Examples of javax.print.PrintException


     * Starts parsing of source postscript and rendering
     * to print service's device context.
     */
    public void interpret() throws PrintException {
        if (serviceID < 0) {
            throw new PrintException(
                    "Unrecoverable internal error in GDI client.");
        }
        try {
            currentLine = source.readLine();
            while (currentLine != null) {
                if (currentLine.startsWith("%%EOF")) {
//                    /*
//                     * Code for debug. Prints additional page.
//                     */
//                    startPage(serviceID);
//                    setRGBColor(serviceID, 0.5, 0.5, 0.5);
//                    moveTo(serviceID, 50, 50);
//                    drawText(serviceID, "TEXT TEXT TEXT");
//                    endPage(serviceID);
                    if (!endDocument(serviceID)) {
                        releaseServiceID(serviceID);
                        serviceID = -1;
                        throw new PrintException(
                                "Unable to finish document printing.");
                    }
                    releaseServiceID(serviceID);
                    serviceID = -1;
                    return;
                } else if (currentLine.startsWith("%%")) {
                    interpretComment();
                } else if (currentLine.startsWith("%") ||
                           currentLine.startsWith("/")) {
                    // Nothing to do - simple comment.
                } else {
                    String lexem = getNextLexem();
                    while (lexem != null) {
//                        System.out.println("Lexem: " + lexem);
                        queue.add(lexem);
                        for (int i = 0; i < commands.length; i++) {
                            if (lexem.equals(commands[i])) {
                                interpretCommand(i);
                            }
                        }
                        lexem = getNextLexem();
                    }
                }
                currentLine = source.readLine();
                lineIndex = 0;
            }
            endDocument(serviceID);
        } catch (IOException ioe) {
            throw new PrintException(
                    "Unrecoverable internal error in GDI client.");
        }
    }
View Full Code Here


                String pageName = getNextLexem(currentLine, 7);
                String pageNumber = getNextLexem(currentLine, searchingIndex);
                int number = Integer.parseInt(pageNumber);
                if (!startPage(serviceID)) {
                    endDocument(serviceID);
                    throw new PrintException("Unable to start page printing.");
                }
            } catch (NumberFormatException nfe) {
                System.out.println("NumberFormatException occured: " + nfe);
                nfe.printStackTrace(System.out);
            }
        } else if (currentLine.startsWith("%%EndPage:")) {
            try {
                String pageName = getNextLexem(currentLine, 10);
                String pageNumber = getNextLexem(currentLine, searchingIndex);
                int number = Integer.parseInt(pageNumber);
                if (pathOpened) {
                    closePath(serviceID);
                    pathOpened = false;
                }
                endPage(serviceID);
            } catch (NumberFormatException nfe) {
                System.out.println("NumberFormatException occured: " + nfe);
                nfe.printStackTrace(System.out);
            }
        } else if (currentLine.startsWith("%%EndSetup") ||
                   currentLine.startsWith("%%EndComments")) {
            if (!startDocument(service, serviceID, client.convertAttributes(
                    attributes,
                    new DocFlavor.INPUT_STREAM("INTERNAL/postscript")),
                    client.getJobName(attributes),
                    client.getDestination(attributes))) {
                throw new PrintException("Unable to start document printing.");
            }
        }
    }
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) {
                final PageFormat format = new PageFormat();
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

                        data = ((URL)doc.getPrintData()).openStream();
                    } else {
                        data = doc.getStreamForBytes();
                    }
                } catch (IOException ioe) {
                    throw new PrintException(
                            "Can't read data from document souce");
                }
                int printerID = startDocPrinter(serviceName,
                        convertAttributes(attributes, flavor),
                        getJobName(attributes), getDestination(attributes));
                if (printerID != 0) {
                    byte[] buffer = new byte[10240];
                    try {
                        int bytesRead = data.read(buffer);
                        while (bytesRead >= 0) {
                            if (!writePrinter(buffer, bytesRead, printerID)) {
                                endDocPrinter(printerID);
                                throw new PrintException(
                                        "Can't send data to printer");
                            }
                            bytesRead = data.read(buffer);
                        }
                    } catch (IOException ioe) {
                        throw new PrintException(
                                "Can't read print data from Doc");
                    }
                    if (!endDocPrinter(printerID)) {
                        throw new PrintException("Can't finish job normally");
                    }
                } else {
                    throw new PrintException("Can't start printing");
                }
            } else if (flavor.getMimeType().toLowerCase().equals(
                           "internal/postscript") &&
                       flavor.getRepresentationClassName().equals(
                           "java.io.InputStream")) {
                InputStream data = null;
                try {
                    data = (InputStream)doc.getPrintData();
                } catch (IOException ioe) {
                    throw new PrintException(
                            "Can't read data from document souce");
                }
                PSInterpreter interpreter = new PSInterpreter(data, serviceName,
                        this, attributes);
                interpreter.interpret();
            } else {
                throw new PrintException("DocFlavor is not supported");
            }
        }
    }
View Full Code Here

        if (attrs != null) {
            if (attrs.containsKey(Destination.class)) {
                Destination destination =
                    (Destination)attrs.get(Destination.class);
                if (!destination.getURI().getScheme().equals("file")) {
                    throw new PrintException(
                            "Only files supported as destinations.");
                }
                String file = destination.getURI().getPath();
                if (file.startsWith("/")) {
                    file = file.substring(1);
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

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.