javax.print.event.PrintJobEvent Java Examples

The following examples show how to use javax.print.event.PrintJobEvent. 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 hottub 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: 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 #3
Source File: UnixPrintJob.java    From hottub 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 #4
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 #5
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 #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: 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 #8
Source File: PSStreamPrintJob.java    From openjdk-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 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 #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: 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 #12
Source File: UnixPrintJob.java    From jdk8u60 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 #13
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 #14
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 #15
Source File: Win32PrintJob.java    From openjdk-8 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 #16
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 #17
Source File: Win32PrintJob.java    From openjdk-8-source 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 #18
Source File: PrintSEUmlauts.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        GraphicsEnvironment.getLocalGraphicsEnvironment();

        DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
        String mime = DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType();

        StreamPrintServiceFactory[] factories =
                StreamPrintServiceFactory.
                        lookupStreamPrintServiceFactories(flavor, mime);
        if (factories.length == 0) {
            System.out.println("No print service found.");
            return;
        }

        FileOutputStream output = new FileOutputStream("out.ps");
        StreamPrintService service = factories[0].getPrintService(output);

        SimpleDoc doc =
             new SimpleDoc(new PrintSEUmlauts(),
                           DocFlavor.SERVICE_FORMATTED.PRINTABLE,
                           new HashDocAttributeSet());
        DocPrintJob job = service.createPrintJob();
        job.addPrintJobListener(new PrintJobAdapter() {
            @Override
            public void printJobCompleted(PrintJobEvent pje) {
                testPrintAndExit();
            }
        });

        job.print(doc, new HashPrintRequestAttributeSet());
    }
 
Example #19
Source File: Win32PrintJob.java    From jdk8u-dev-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 #20
Source File: PSStreamPrintJob.java    From Bytecoder with Apache License 2.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 #21
Source File: PrintSEUmlauts.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        GraphicsEnvironment.getLocalGraphicsEnvironment();

        DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
        String mime = DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType();

        StreamPrintServiceFactory[] factories =
                StreamPrintServiceFactory.
                        lookupStreamPrintServiceFactories(flavor, mime);
        if (factories.length == 0) {
            System.out.println("No print service found.");
            return;
        }

        FileOutputStream output = new FileOutputStream("out.ps");
        StreamPrintService service = factories[0].getPrintService(output);

        SimpleDoc doc =
             new SimpleDoc(new PrintSEUmlauts(),
                           DocFlavor.SERVICE_FORMATTED.PRINTABLE,
                           new HashDocAttributeSet());
        DocPrintJob job = service.createPrintJob();
        job.addPrintJobListener(new PrintJobAdapter() {
            @Override
            public void printJobCompleted(PrintJobEvent pje) {
                testPrintAndExit();
            }
        });

        job.print(doc, new HashPrintRequestAttributeSet());
    }
 
Example #22
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 #23
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 #24
Source File: UnixPrintJob.java    From openjdk-jdk8u 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 #25
Source File: Win32PrintJob.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 #26
Source File: UnixPrintJob.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public Object run() {
    if (spoolFile == null || !spoolFile.exists()) {
       pex = new PrintException("No spool file");
       notifyEvent(PrintJobEvent.JOB_FAILED);
       return null;
    }
    try {
        /**
         * Spool to the printer.
         */
        String fileName = spoolFile.getAbsolutePath();
        String execCmd[] = printExecCmd(mDestination, mOptions,
                       mNoJobSheet, jobName, copies, fileName);

        Process process = Runtime.getRuntime().exec(execCmd);
        process.waitFor();
        final int result = process.exitValue();
        if (0 != result) {
            handleProcessFailure(process, execCmd, result);
        }
        notifyEvent(PrintJobEvent.DATA_TRANSFER_COMPLETE);
    } catch (IOException ex) {
        notifyEvent(PrintJobEvent.JOB_FAILED);
        // REMIND : 2d printing throws PrinterException
        pex = new PrintException(ex);
    } catch (InterruptedException ie) {
        notifyEvent(PrintJobEvent.JOB_FAILED);
        pex = new PrintException(ie);
    } finally {
        spoolFile.delete();
        notifyEvent(PrintJobEvent.NO_MORE_EVENTS);
    }
    return null;
}
 
Example #27
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.");
        }
    }
}
 
Example #28
Source File: UnixPrintJob.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public Object run() {
    if (spoolFile == null || !spoolFile.exists()) {
       pex = new PrintException("No spool file");
       notifyEvent(PrintJobEvent.JOB_FAILED);
       return null;
    }
    try {
        /**
         * Spool to the printer.
         */
        String fileName = spoolFile.getAbsolutePath();
        String execCmd[] = printExecCmd(mDestination, mOptions,
                       mNoJobSheet, jobName, copies, fileName);

        Process process = Runtime.getRuntime().exec(execCmd);
        process.waitFor();
        final int result = process.exitValue();
        if (0 != result) {
            handleProcessFailure(process, execCmd, result);
        }
        notifyEvent(PrintJobEvent.DATA_TRANSFER_COMPLETE);
    } catch (IOException ex) {
        notifyEvent(PrintJobEvent.JOB_FAILED);
        // REMIND : 2d printing throws PrinterException
        pex = new PrintException(ex);
    } catch (InterruptedException ie) {
        notifyEvent(PrintJobEvent.JOB_FAILED);
        pex = new PrintException(ie);
    } finally {
        spoolFile.delete();
        notifyEvent(PrintJobEvent.NO_MORE_EVENTS);
    }
    return null;
}
 
Example #29
Source File: PSStreamPrintJob.java    From jdk8u_jdk 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 #30
Source File: PSStreamPrintJob.java    From jdk8u-jdk 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;
    }
}