javax.print.PrintException Java Examples

The following examples show how to use javax.print.PrintException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UnixPrintJob.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public Object run() {
    try {
        if (mDestType == UnixPrintJob.DESTFILE) {
            spoolFile = new File(mDestination);
        } else {
            /* Write to a temporary file which will be spooled to
             * the printer then deleted. In the case that the file
             * is not removed for some reason, request that it is
             * removed when the VM exits.
             */
            spoolFile = Files.createTempFile("javaprint", "").toFile();
            spoolFile.deleteOnExit();
        }
        result = new FileOutputStream(spoolFile);
        return result;
    } catch (IOException ex) {
        // If there is an IOError we subvert it to a PrinterException.
        notifyEvent(PrintJobEvent.JOB_FAILED);
        pex = new PrintException(ex);
    }
    return null;
}
 
Example #2
Source File: PSStreamPrintJob.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public void pageableJob(Pageable pageable,
                        PrintRequestAttributeSet attributes)
    throws PrintException {
    try {
        synchronized(this) {
            if (job != null) { // shouldn't happen
                throw new PrintException("already printing");
            } else {
                job = new PSPrinterJob();
            }
        }
        job.setPrintService(getPrintService());
        job.setPageable(pageable);
        job.print(attributes);
        notifyEvent(PrintJobEvent.JOB_COMPLETE);
        return;
    } catch (PrinterException pe) {
        notifyEvent(PrintJobEvent.JOB_FAILED);
        throw new PrintException(pe);
    } finally {
        printReturned = true;
    }
}
 
Example #3
Source File: UnixPrintJob.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public void printableJob(Printable printable) throws PrintException {
    try {
        synchronized(this) {
            if (job != null) { // shouldn't happen
                throw new PrintException("already printing");
            } else {
                job = new PSPrinterJob();
            }
        }
        job.setPrintService(getPrintService());
        job.setCopies(copies);
        job.setJobName(jobName);
        PageFormat pf = new PageFormat();
        if (mediaSize != null) {
            Paper p = new Paper();
            p.setSize(mediaSize.getX(MediaSize.INCH)*72.0,
                      mediaSize.getY(MediaSize.INCH)*72.0);
            p.setImageableArea(72.0, 72.0, p.getWidth()-144.0,
                               p.getHeight()-144.0);
            pf.setPaper(p);
        }
        if (orient == OrientationRequested.REVERSE_LANDSCAPE) {
            pf.setOrientation(PageFormat.REVERSE_LANDSCAPE);
        } else if (orient == OrientationRequested.LANDSCAPE) {
            pf.setOrientation(PageFormat.LANDSCAPE);
        }
        job.setPrintable(printable, pf);
        job.print(reqAttrSet);
        notifyEvent(PrintJobEvent.DATA_TRANSFER_COMPLETE);
        return;
    } catch (PrinterException pe) {
        notifyEvent(PrintJobEvent.JOB_FAILED);
        throw new PrintException(pe);
    } finally {
        printReturned = true;
        notifyEvent(PrintJobEvent.NO_MORE_EVENTS);
    }
}
 
Example #4
Source File: UnixPrintJob.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public void pageableJob(Pageable pageable) throws PrintException {
    try {
        synchronized(this) {
            if (job != null) { // shouldn't happen
                throw new PrintException("already printing");
            } else {
                job = new PSPrinterJob();
            }
        }
        job.setPrintService(getPrintService());
        job.setCopies(copies);
        job.setJobName(jobName);
        job.setPageable(pageable);
        job.print(reqAttrSet);
        notifyEvent(PrintJobEvent.DATA_TRANSFER_COMPLETE);
        return;
    } catch (PrinterException pe) {
        notifyEvent(PrintJobEvent.JOB_FAILED);
        throw new PrintException(pe);
    } finally {
        printReturned = true;
        notifyEvent(PrintJobEvent.NO_MORE_EVENTS);
    }
}
 
Example #5
Source File: PSStreamPrintJob.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
public void pageableJob(Pageable pageable,
                        PrintRequestAttributeSet attributes)
    throws PrintException {
    try {
        synchronized(this) {
            if (job != null) { // shouldn't happen
                throw new PrintException("already printing");
            } else {
                job = new PSPrinterJob();
            }
        }
        job.setPrintService(getPrintService());
        job.setPageable(pageable);
        job.print(attributes);
        notifyEvent(PrintJobEvent.JOB_COMPLETE);
        return;
    } catch (PrinterException pe) {
        notifyEvent(PrintJobEvent.JOB_FAILED);
        throw new PrintException(pe);
    } finally {
        printReturned = true;
    }
}
 
Example #6
Source File: UnixPrintJob.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public Object run() {
    try {
        if (mDestType == UnixPrintJob.DESTFILE) {
            spoolFile = new File(mDestination);
        } else {
            /* Write to a temporary file which will be spooled to
             * the printer then deleted. In the case that the file
             * is not removed for some reason, request that it is
             * removed when the VM exits.
             */
            spoolFile = Files.createTempFile("javaprint", "").toFile();
            spoolFile.deleteOnExit();
        }
        result = new FileOutputStream(spoolFile);
        return result;
    } catch (IOException ex) {
        // If there is an IOError we subvert it to a PrinterException.
        notifyEvent(PrintJobEvent.JOB_FAILED);
        pex = new PrintException(ex);
    }
    return null;
}
 
Example #7
Source File: PrinterOutputStream.java    From escpos-coffee with MIT License 6 votes vote down vote up
/**
 * creates one instance of PrinterOutputStream.
 * <p>
 * Create one print based on print service. Start print job linked (this)
 * output stream.
 *
 * @param printService value used to create the printer job
 * @exception IOException if an I/O error occurs.
 * @see #getPrintServiceByName(java.lang.String)
 * @see #getDefaultPrintService()
 */
public PrinterOutputStream(PrintService printService) throws IOException {

    UncaughtExceptionHandler uncaughtException = (Thread t, Throwable e) -> {
        Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, e.getMessage(),e);
    };

    pipedInputStream = new PipedInputStream();
    super.connect(pipedInputStream);

    Runnable runnablePrint = () -> {
        try {
            DocFlavor df = DocFlavor.INPUT_STREAM.AUTOSENSE;
            Doc d = new SimpleDoc(pipedInputStream, df, null);

            DocPrintJob job = printService.createPrintJob();
            job.print(d, null);
        } catch (PrintException ex) {
            throw new RuntimeException(ex);
        }
    };

    threadPrint = new Thread(runnablePrint);
    threadPrint.setUncaughtExceptionHandler(uncaughtException);
    threadPrint.start();
}
 
Example #8
Source File: PSStreamPrintJob.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public void pageableJob(Pageable pageable,
                        PrintRequestAttributeSet attributes)
    throws PrintException {
    try {
        synchronized(this) {
            if (job != null) { // shouldn't happen
                throw new PrintException("already printing");
            } else {
                job = new PSPrinterJob();
            }
        }
        job.setPrintService(getPrintService());
        job.setPageable(pageable);
        job.print(attributes);
        notifyEvent(PrintJobEvent.JOB_COMPLETE);
        return;
    } catch (PrinterException pe) {
        notifyEvent(PrintJobEvent.JOB_FAILED);
        throw new PrintException(pe);
    } finally {
        printReturned = true;
    }
}
 
Example #9
Source File: UnixPrintJob.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public void pageableJob(Pageable pageable) throws PrintException {
    try {
        synchronized(this) {
            if (job != null) { // shouldn't happen
                throw new PrintException("already printing");
            } else {
                job = new PSPrinterJob();
            }
        }
        job.setPrintService(getPrintService());
        job.setCopies(copies);
        job.setJobName(jobName);
        job.setPageable(pageable);
        job.print(reqAttrSet);
        notifyEvent(PrintJobEvent.DATA_TRANSFER_COMPLETE);
        return;
    } catch (PrinterException pe) {
        notifyEvent(PrintJobEvent.JOB_FAILED);
        throw new PrintException(pe);
    } finally {
        printReturned = true;
        notifyEvent(PrintJobEvent.NO_MORE_EVENTS);
    }
}
 
Example #10
Source File: UnixPrintJob.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public void pageableJob(Pageable pageable) throws PrintException {
    try {
        synchronized(this) {
            if (job != null) { // shouldn't happen
                throw new PrintException("already printing");
            } else {
                job = new PSPrinterJob();
            }
        }
        job.setPrintService(getPrintService());
        job.setCopies(copies);
        job.setJobName(jobName);
        job.setPageable(pageable);
        job.print(reqAttrSet);
        notifyEvent(PrintJobEvent.DATA_TRANSFER_COMPLETE);
        return;
    } catch (PrinterException pe) {
        notifyEvent(PrintJobEvent.JOB_FAILED);
        throw new PrintException(pe);
    } finally {
        printReturned = true;
        notifyEvent(PrintJobEvent.NO_MORE_EVENTS);
    }
}
 
Example #11
Source File: UnixPrintJob.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public void pageableJob(Pageable pageable) throws PrintException {
    try {
        synchronized(this) {
            if (job != null) { // shouldn't happen
                throw new PrintException("already printing");
            } else {
                job = new PSPrinterJob();
            }
        }
        job.setPrintService(getPrintService());
        job.setCopies(copies);
        job.setJobName(jobName);
        job.setPageable(pageable);
        job.print(reqAttrSet);
        notifyEvent(PrintJobEvent.DATA_TRANSFER_COMPLETE);
        return;
    } catch (PrinterException pe) {
        notifyEvent(PrintJobEvent.JOB_FAILED);
        throw new PrintException(pe);
    } finally {
        printReturned = true;
        notifyEvent(PrintJobEvent.NO_MORE_EVENTS);
    }
}
 
Example #12
Source File: UnixPrintJob.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public OutputStream run() {
    try {
        if (mDestType == UnixPrintJob.DESTFILE) {
            spoolFile = new File(mDestination);
        } else {
            /* Write to a temporary file which will be spooled to
             * the printer then deleted. In the case that the file
             * is not removed for some reason, request that it is
             * removed when the VM exits.
             */
            spoolFile = Files.createTempFile("javaprint", "").toFile();
            spoolFile.deleteOnExit();
        }
        result = new FileOutputStream(spoolFile);
        return result;
    } catch (IOException ex) {
        // If there is an IOError we subvert it to a PrinterException.
        notifyEvent(PrintJobEvent.JOB_FAILED);
        pex = new PrintException(ex);
    }
    return null;
}
 
Example #13
Source File: UnixPrintJob.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public Object run() {
    try {
        if (mDestType == UnixPrintJob.DESTFILE) {
            spoolFile = new File(mDestination);
        } else {
            /* Write to a temporary file which will be spooled to
             * the printer then deleted. In the case that the file
             * is not removed for some reason, request that it is
             * removed when the VM exits.
             */
            spoolFile = Files.createTempFile("javaprint", "").toFile();
            spoolFile.deleteOnExit();
        }
        result = new FileOutputStream(spoolFile);
        return result;
    } catch (IOException ex) {
        // If there is an IOError we subvert it to a PrinterException.
        notifyEvent(PrintJobEvent.JOB_FAILED);
        pex = new PrintException(ex);
    }
    return null;
}
 
Example #14
Source File: PSStreamPrintJob.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public void pageableJob(Pageable pageable,
                        PrintRequestAttributeSet attributes)
    throws PrintException {
    try {
        synchronized(this) {
            if (job != null) { // shouldn't happen
                throw new PrintException("already printing");
            } else {
                job = new PSPrinterJob();
            }
        }
        job.setPrintService(getPrintService());
        job.setPageable(pageable);
        job.print(attributes);
        notifyEvent(PrintJobEvent.JOB_COMPLETE);
        return;
    } catch (PrinterException pe) {
        notifyEvent(PrintJobEvent.JOB_FAILED);
        throw new PrintException(pe);
    } finally {
        printReturned = true;
    }
}
 
Example #15
Source File: PSStreamPrintJob.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public void pageableJob(Pageable pageable,
                        PrintRequestAttributeSet attributes)
    throws PrintException {
    try {
        synchronized(this) {
            if (job != null) { // shouldn't happen
                throw new PrintException("already printing");
            } else {
                job = new PSPrinterJob();
            }
        }
        job.setPrintService(getPrintService());
        job.setPageable(pageable);
        job.print(attributes);
        notifyEvent(PrintJobEvent.JOB_COMPLETE);
        return;
    } catch (PrinterException pe) {
        notifyEvent(PrintJobEvent.JOB_FAILED);
        throw new PrintException(pe);
    } finally {
        printReturned = true;
    }
}
 
Example #16
Source File: PSStreamPrintJob.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public void pageableJob(Pageable pageable,
                        PrintRequestAttributeSet attributes)
    throws PrintException {
    try {
        synchronized(this) {
            if (job != null) { // shouldn't happen
                throw new PrintException("already printing");
            } else {
                job = new PSPrinterJob();
            }
        }
        job.setPrintService(getPrintService());
        job.setPageable(pageable);
        job.print(attributes);
        notifyEvent(PrintJobEvent.JOB_COMPLETE);
        return;
    } catch (PrinterException pe) {
        notifyEvent(PrintJobEvent.JOB_FAILED);
        throw new PrintException(pe);
    } finally {
        printReturned = true;
    }
}
 
Example #17
Source File: UnixPrintJob.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public Object run() {
    try {
        if (mDestType == UnixPrintJob.DESTFILE) {
            spoolFile = new File(mDestination);
        } else {
            /* Write to a temporary file which will be spooled to
             * the printer then deleted. In the case that the file
             * is not removed for some reason, request that it is
             * removed when the VM exits.
             */
            spoolFile = Files.createTempFile("javaprint", "").toFile();
            spoolFile.deleteOnExit();
        }
        result = new FileOutputStream(spoolFile);
        return result;
    } catch (IOException ex) {
        // If there is an IOError we subvert it to a PrinterException.
        notifyEvent(PrintJobEvent.JOB_FAILED);
        pex = new PrintException(ex);
    }
    return null;
}
 
Example #18
Source File: PSStreamPrintJob.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public void pageableJob(Pageable pageable,
                        PrintRequestAttributeSet attributes)
    throws PrintException {
    try {
        synchronized(this) {
            if (job != null) { // shouldn't happen
                throw new PrintException("already printing");
            } else {
                job = new PSPrinterJob();
            }
        }
        job.setPrintService(getPrintService());
        job.setPageable(pageable);
        job.print(attributes);
        notifyEvent(PrintJobEvent.JOB_COMPLETE);
        return;
    } catch (PrinterException pe) {
        notifyEvent(PrintJobEvent.JOB_FAILED);
        throw new PrintException(pe);
    } finally {
        printReturned = true;
    }
}
 
Example #19
Source File: UnixPrintJob.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public void pageableJob(Pageable pageable) throws PrintException {
    try {
        synchronized(this) {
            if (job != null) { // shouldn't happen
                throw new PrintException("already printing");
            } else {
                job = new PSPrinterJob();
            }
        }
        job.setPrintService(getPrintService());
        job.setCopies(copies);
        job.setJobName(jobName);
        job.setPageable(pageable);
        job.print(reqAttrSet);
        notifyEvent(PrintJobEvent.DATA_TRANSFER_COMPLETE);
        return;
    } catch (PrinterException pe) {
        notifyEvent(PrintJobEvent.JOB_FAILED);
        throw new PrintException(pe);
    } finally {
        printReturned = true;
        notifyEvent(PrintJobEvent.NO_MORE_EVENTS);
    }
}
 
Example #20
Source File: PSStreamPrintJob.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public void pageableJob(Pageable pageable,
                        PrintRequestAttributeSet attributes)
    throws PrintException {
    try {
        synchronized(this) {
            if (job != null) { // shouldn't happen
                throw new PrintException("already printing");
            } else {
                job = new PSPrinterJob();
            }
        }
        job.setPrintService(getPrintService());
        job.setPageable(pageable);
        job.print(attributes);
        notifyEvent(PrintJobEvent.JOB_COMPLETE);
        return;
    } catch (PrinterException pe) {
        notifyEvent(PrintJobEvent.JOB_FAILED);
        throw new PrintException(pe);
    } finally {
        printReturned = true;
    }
}
 
Example #21
Source File: UnixPrintJob.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void cancel() throws PrintException {
    synchronized (this) {
        if (!printing) {
            throw new PrintException("Job is not yet submitted.");
        } else if (job != null && !printReturned) {
            job.cancel();
            notifyEvent(PrintJobEvent.JOB_CANCELED);
            return;
        } else {
            throw new PrintException("Job could not be cancelled.");
        }
    }
}
 
Example #22
Source File: PSStreamPrintJob.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void printableJob(Printable printable,
                         PrintRequestAttributeSet attributes)
    throws PrintException {
    try {
        synchronized(this) {
            if (job != null) { // shouldn't happen
                throw new PrintException("already printing");
            } else {
                job = new PSPrinterJob();
            }
        }
        job.setPrintService(getPrintService());
        PageFormat pf = new PageFormat();
        if (mediaSize != null) {
            Paper p = new Paper();
            p.setSize(mediaSize.getX(MediaSize.INCH)*72.0,
                      mediaSize.getY(MediaSize.INCH)*72.0);
            p.setImageableArea(72.0, 72.0, p.getWidth()-144.0,
                               p.getHeight()-144.0);
            pf.setPaper(p);
        }
        if (orient == OrientationRequested.REVERSE_LANDSCAPE) {
            pf.setOrientation(PageFormat.REVERSE_LANDSCAPE);
        } else if (orient == OrientationRequested.LANDSCAPE) {
            pf.setOrientation(PageFormat.LANDSCAPE);
        }
        job.setPrintable(printable, pf);
        job.print(attributes);
        notifyEvent(PrintJobEvent.JOB_COMPLETE);
        return;
    } catch (PrinterException pe) {
        notifyEvent(PrintJobEvent.JOB_FAILED);
        throw new PrintException(pe);
    } finally {
        printReturned = true;
    }
}
 
Example #23
Source File: Win32PrintJob.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void pageableJob(Pageable pageable) throws PrintException {
    try {
        synchronized(this) {
            if (job != null) { // shouldn't happen
                throw new PrintException("already printing");
            } else {
                job = new sun.awt.windows.WPrinterJob();
            }
        }
        PrintService svc = getPrintService();
        job.setPrintService(svc);
        if (copies == 0) {
            Copies c = (Copies)svc.getDefaultAttributeValue(Copies.class);
            copies = c.getValue();
        }
        job.setCopies(copies);
        job.setJobName(jobName);
        job.setPageable(pageable);
        job.print(reqAttrSet);
        notifyEvent(PrintJobEvent.DATA_TRANSFER_COMPLETE);
        return;
    } catch (PrinterException pe) {
        notifyEvent(PrintJobEvent.JOB_FAILED);
        throw new PrintException(pe);
    } finally {
        printReturned = true;
        notifyEvent(PrintJobEvent.NO_MORE_EVENTS);
    }
}
 
Example #24
Source File: PSStreamPrintJob.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void printableJob(Printable printable,
                         PrintRequestAttributeSet attributes)
    throws PrintException {
    try {
        synchronized(this) {
            if (job != null) { // shouldn't happen
                throw new PrintException("already printing");
            } else {
                job = new PSPrinterJob();
            }
        }
        job.setPrintService(getPrintService());
        PageFormat pf = new PageFormat();
        if (mediaSize != null) {
            Paper p = new Paper();
            p.setSize(mediaSize.getX(MediaSize.INCH)*72.0,
                      mediaSize.getY(MediaSize.INCH)*72.0);
            p.setImageableArea(72.0, 72.0, p.getWidth()-144.0,
                               p.getHeight()-144.0);
            pf.setPaper(p);
        }
        if (orient == OrientationRequested.REVERSE_LANDSCAPE) {
            pf.setOrientation(PageFormat.REVERSE_LANDSCAPE);
        } else if (orient == OrientationRequested.LANDSCAPE) {
            pf.setOrientation(PageFormat.LANDSCAPE);
        }
        job.setPrintable(printable, pf);
        job.print(attributes);
        notifyEvent(PrintJobEvent.JOB_COMPLETE);
        return;
    } catch (PrinterException pe) {
        notifyEvent(PrintJobEvent.JOB_FAILED);
        throw new PrintException(pe);
    } finally {
        printReturned = true;
    }
}
 
Example #25
Source File: Win32PrintJob.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void cancel() throws PrintException {
    synchronized (this) {
        if (!printing) {
            throw new PrintException("Job is not yet submitted.");
        } else if (job != null && !printReturned) {
            job.cancel();
            notifyEvent(PrintJobEvent.JOB_CANCELED);
            return;
        } else {
            throw new PrintException("Job could not be cancelled.");
        }
    }
}
 
Example #26
Source File: UnixPrintJob.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void printableJob(Printable printable) throws PrintException {
    try {
        synchronized(this) {
            if (job != null) { // shouldn't happen
                throw new PrintException("already printing");
            } else {
                job = new PSPrinterJob();
            }
        }
        job.setPrintService(getPrintService());
        job.setCopies(copies);
        job.setJobName(jobName);
        PageFormat pf = new PageFormat();
        if (mediaSize != null) {
            Paper p = new Paper();
            p.setSize(mediaSize.getX(MediaSize.INCH)*72.0,
                      mediaSize.getY(MediaSize.INCH)*72.0);
            p.setImageableArea(72.0, 72.0, p.getWidth()-144.0,
                               p.getHeight()-144.0);
            pf.setPaper(p);
        }
        if (orient == OrientationRequested.REVERSE_LANDSCAPE) {
            pf.setOrientation(PageFormat.REVERSE_LANDSCAPE);
        } else if (orient == OrientationRequested.LANDSCAPE) {
            pf.setOrientation(PageFormat.LANDSCAPE);
        }
        job.setPrintable(printable, pf);
        job.print(reqAttrSet);
        notifyEvent(PrintJobEvent.DATA_TRANSFER_COMPLETE);
        return;
    } catch (PrinterException pe) {
        notifyEvent(PrintJobEvent.JOB_FAILED);
        throw new PrintException(pe);
    } finally {
        printReturned = true;
        notifyEvent(PrintJobEvent.NO_MORE_EVENTS);
    }
}
 
Example #27
Source File: UnixPrintJob.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void cancel() throws PrintException {
    synchronized (this) {
        if (!printing) {
            throw new PrintException("Job is not yet submitted.");
        } else if (job != null && !printReturned) {
            job.cancel();
            notifyEvent(PrintJobEvent.JOB_CANCELED);
            return;
        } else {
            throw new PrintException("Job could not be cancelled.");
        }
    }
}
 
Example #28
Source File: UnixPrintJob.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public void printableJob(Printable printable) throws PrintException {
    try {
        synchronized(this) {
            if (job != null) { // shouldn't happen
                throw new PrintException("already printing");
            } else {
                job = new PSPrinterJob();
            }
        }
        job.setPrintService(getPrintService());
        job.setCopies(copies);
        job.setJobName(jobName);
        PageFormat pf = new PageFormat();
        if (mediaSize != null) {
            Paper p = new Paper();
            p.setSize(mediaSize.getX(MediaSize.INCH)*72.0,
                      mediaSize.getY(MediaSize.INCH)*72.0);
            p.setImageableArea(72.0, 72.0, p.getWidth()-144.0,
                               p.getHeight()-144.0);
            pf.setPaper(p);
        }
        if (orient == OrientationRequested.REVERSE_LANDSCAPE) {
            pf.setOrientation(PageFormat.REVERSE_LANDSCAPE);
        } else if (orient == OrientationRequested.LANDSCAPE) {
            pf.setOrientation(PageFormat.LANDSCAPE);
        }
        job.setPrintable(printable, pf);
        job.print(reqAttrSet);
        notifyEvent(PrintJobEvent.DATA_TRANSFER_COMPLETE);
        return;
    } catch (PrinterException pe) {
        notifyEvent(PrintJobEvent.JOB_FAILED);
        throw new PrintException(pe);
    } finally {
        printReturned = true;
        notifyEvent(PrintJobEvent.NO_MORE_EVENTS);
    }
}
 
Example #29
Source File: Win32PrintJob.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public void cancel() throws PrintException {
    synchronized (this) {
        if (!printing) {
            throw new PrintException("Job is not yet submitted.");
        } else if (job != null && !printReturned) {
            job.cancel();
            notifyEvent(PrintJobEvent.JOB_CANCELED);
            return;
        } else {
            throw new PrintException("Job could not be cancelled.");
        }
    }
}
 
Example #30
Source File: PSStreamPrintJob.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void cancel() throws PrintException {
    synchronized (this) {
        if (!printing) {
            throw new PrintException("Job is not yet submitted.");
        } else if (job != null && !printReturned) {
            job.cancel();
            notifyEvent(PrintJobEvent.JOB_CANCELED);
            return;
        } else {
            throw new PrintException("Job could not be cancelled.");
        }
    }
}