javax.print.StreamPrintService Java Examples

The following examples show how to use javax.print.StreamPrintService. 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: PrintUtils.java    From osp with GNU General Public License v3.0 6 votes vote down vote up
public static void saveComponentAsEPS(Component c) throws IOException {
  // Find a factory object for printing Printable objects to PostScript.
  DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
  String format = "application/postscript"; //$NON-NLS-1$
  StreamPrintServiceFactory factory = StreamPrintServiceFactory.lookupStreamPrintServiceFactories(flavor, format)[0];
  // Ask the user to select a file and open the selected file
  //JFileChooser chooser = new JFileChooser();
  JFileChooser chooser = OSPRuntime.getChooser();
  if(chooser.showSaveDialog(c)!=JFileChooser.APPROVE_OPTION) {
    return;
  }
  File f = chooser.getSelectedFile();
  FileOutputStream out = new FileOutputStream(f);
  // Obtain a PrintService that prints to that file
  StreamPrintService service = factory.getPrintService(out);
  // Do the printing with the method below
  printToService(c, service, null);
  // And close the output file.
  out.close();
}
 
Example #2
Source File: RasterPrinterJob.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Associate this PrinterJob with a new PrintService.
 *
 * Throws <code>PrinterException</code> if the specified service
 * cannot support the <code>Pageable</code> and
 * <code>Printable</code> interfaces necessary to support 2D printing.
 * @param a print service which supports 2D printing.
 *
 * @throws PrinterException if the specified service does not support
 * 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);
        }
    }
}
 
Example #3
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 #4
Source File: RasterPrinterJob.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Associate this PrinterJob with a new PrintService.
 *
 * Throws <code>PrinterException</code> if the specified service
 * cannot support the <code>Pageable</code> and
 * <code>Printable</code> interfaces necessary to support 2D printing.
 * @param a print service which supports 2D printing.
 *
 * @throws PrinterException if the specified service does not support
 * 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);
        }
    }
}
 
Example #5
Source File: PrintSEUmlauts.java    From jdk8u-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 #6
Source File: RasterPrinterJob.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Associate this PrinterJob with a new PrintService.
 *
 * Throws <code>PrinterException</code> if the specified service
 * cannot support the <code>Pageable</code> and
 * <code>Printable</code> interfaces necessary to support 2D printing.
 * @param a print service which supports 2D printing.
 *
 * @throws PrinterException if the specified service does not support
 * 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);
        }
    }
}
 
Example #7
Source File: PrintSEUmlauts.java    From jdk8u_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 #8
Source File: RasterPrinterJob.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Associate this PrinterJob with a new PrintService.
 *
 * Throws <code>PrinterException</code> if the specified service
 * cannot support the <code>Pageable</code> and
 * <code>Printable</code> interfaces necessary to support 2D printing.
 * @param a print service which supports 2D printing.
 *
 * @throws PrinterException if the specified service does not support
 * 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);
        }
    }
}
 
Example #9
Source File: RasterPrinterJob.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Associate this PrinterJob with a new PrintService.
 *
 * Throws <code>PrinterException</code> if the specified service
 * cannot support the <code>Pageable</code> and
 * <code>Printable</code> interfaces necessary to support 2D printing.
 * @param a print service which supports 2D printing.
 *
 * @throws PrinterException if the specified service does not support
 * 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);
        }
    }
}
 
Example #10
Source File: RasterPrinterJob.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Associate this PrinterJob with a new PrintService.
 *
 * Throws <code>PrinterException</code> if the specified service
 * cannot support the <code>Pageable</code> and
 * <code>Printable</code> interfaces necessary to support 2D printing.
 * @param a print service which supports 2D printing.
 *
 * @throws PrinterException if the specified service does not support
 * 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);
        }
    }
}
 
Example #11
Source File: PrintSEUmlauts.java    From hottub 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 #12
Source File: RasterPrinterJob.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Associate this PrinterJob with a new PrintService.
 *
 * Throws <code>PrinterException</code> if the specified service
 * cannot support the <code>Pageable</code> and
 * <code>Printable</code> interfaces necessary to support 2D printing.
 * @param a print service which supports 2D printing.
 *
 * @throws PrinterException if the specified service does not support
 * 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);
        }
    }
}
 
Example #13
Source File: PrintSEUmlauts.java    From jdk8u-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 #14
Source File: RasterPrinterJob.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Associate this PrinterJob with a new PrintService.
 *
 * Throws <code>PrinterException</code> if the specified service
 * cannot support the <code>Pageable</code> and
 * <code>Printable</code> interfaces necessary to support 2D printing.
 * @param a print service which supports 2D printing.
 *
 * @throws PrinterException if the specified service does not support
 * 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);
        }
    }
}
 
Example #15
Source File: PrintSEUmlauts.java    From openjdk-jdk9 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 #16
Source File: RasterPrinterJob.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Associate this PrinterJob with a new PrintService.
 *
 * Throws {@code PrinterException} if the specified service
 * cannot support the {@code Pageable} and
 * {@code Printable} interfaces necessary to support 2D printing.
 * @param service print service which supports 2D printing.
 *
 * @throws PrinterException if the specified service does not support
 * 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 = service.getAttribute(PrinterState.class);
        if (prnState == PrinterState.STOPPED) {
            PrinterStateReasons prnStateReasons =
                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);
        }
    }
}
 
Example #17
Source File: PrintSEUmlauts.java    From openjdk-jdk8u-backup 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 #18
Source File: PrintSEUmlauts.java    From dragonwell8_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: RasterPrinterJob.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Associate this PrinterJob with a new PrintService.
 *
 * Throws <code>PrinterException</code> if the specified service
 * cannot support the <code>Pageable</code> and
 * <code>Printable</code> interfaces necessary to support 2D printing.
 * @param a print service which supports 2D printing.
 *
 * @throws PrinterException if the specified service does not support
 * 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);
        }
    }
}
 
Example #20
Source File: PrintSEUmlauts.java    From openjdk-jdk8u 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 #21
Source File: RasterPrinterJob.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Associate this PrinterJob with a new PrintService.
 *
 * Throws <code>PrinterException</code> if the specified service
 * cannot support the <code>Pageable</code> and
 * <code>Printable</code> interfaces necessary to support 2D printing.
 * @param a print service which supports 2D printing.
 *
 * @throws PrinterException if the specified service does not support
 * 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);
        }
    }
}
 
Example #22
Source File: RasterPrinterJob.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Associate this PrinterJob with a new PrintService.
 *
 * Throws <code>PrinterException</code> if the specified service
 * cannot support the <code>Pageable</code> and
 * <code>Printable</code> interfaces necessary to support 2D printing.
 * @param a print service which supports 2D printing.
 *
 * @throws PrinterException if the specified service does not support
 * 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);
        }
    }
}
 
Example #23
Source File: PrintSEUmlauts.java    From TencentKona-8 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 #24
Source File: RasterPrinterJob.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Associate this PrinterJob with a new PrintService.
 *
 * Throws {@code PrinterException} if the specified service
 * cannot support the {@code Pageable} and
 * {@code Printable} interfaces necessary to support 2D printing.
 * @param service print service which supports 2D printing.
 *
 * @throws PrinterException if the specified service does not support
 * 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 = service.getAttribute(PrinterState.class);
        if (prnState == PrinterState.STOPPED) {
            PrinterStateReasons prnStateReasons =
                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);
        }
    }
}
 
Example #25
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 #26
Source File: RasterPrinterJob.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Associate this PrinterJob with a new PrintService.
 *
 * Throws <code>PrinterException</code> if the specified service
 * cannot support the <code>Pageable</code> and
 * <code>Printable</code> interfaces necessary to support 2D printing.
 * @param a print service which supports 2D printing.
 *
 * @throws PrinterException if the specified service does not support
 * 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);
        }
    }
}
 
Example #27
Source File: PSStreamPrinterFactory.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public StreamPrintService getPrintService(OutputStream out) {
    return new PSStreamPrintService(out);
}
 
Example #28
Source File: PSStreamPrinterFactory.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public StreamPrintService getPrintService(OutputStream out) {
    return new PSStreamPrintService(out);
}
 
Example #29
Source File: ChartPanel.java    From opensim-gui with Apache License 2.0 4 votes vote down vote up
private void createChartPrintPostScriptJob() {
// Use the pre-defined flavor for a Printable from an InputStream 
	DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;

		// Specify the type of the output stream 
	String psMimeType = DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType();

	// Locate factory which can export a GIF image stream as Postscript 
	StreamPrintServiceFactory[] factories =
	StreamPrintServiceFactory.lookupStreamPrintServiceFactories(
				flavor, psMimeType);
	if (factories.length == 0) {
		System.err.println("No suitable factories");
		System.exit(0); // FIXME too
	}
               // Obtain file name from user
               JFileChooser fileChooser = new JFileChooser();
               ExtensionFileFilter filter = new ExtensionFileFilter(
                       localizationResources.getString("PostScript_Files"), ".eps");
               fileChooser.addChoosableFileFilter(filter);
               String filename="";
               int option = fileChooser.showSaveDialog(this);
               if (option == JFileChooser.APPROVE_OPTION) {
                  filename = fileChooser.getSelectedFile().getPath();
                  if (isEnforceFileExtensions()) {
                     if (!filename.endsWith(".eps")) {
                        filename = filename + ".eps";
                     }
                  } else
                     return;
               }

	try {
		// Create a file for the exported postscript
		FileOutputStream fos = new FileOutputStream(filename);

		// Create a Stream printer for Postscript 
		StreamPrintService sps = factories[0].getPrintService(fos);

		// Create and call a Print Job 
		DocPrintJob pj = sps.createPrintJob();
		PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();

		Doc doc = new SimpleDoc(this, flavor, null);

		pj.print(doc, aset);
		fos.close();

	} catch (PrintException pe) { 
		System.err.println(pe);
	} catch (IOException ie) { 
		System.err.println(ie);
	}

  }
 
Example #30
Source File: PSStreamPrinterFactory.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public StreamPrintService getPrintService(OutputStream out) {
    return new PSStreamPrintService(out);
}