Example usage for javax.print StreamPrintServiceFactory getPrintService

List of usage examples for javax.print StreamPrintServiceFactory getPrintService

Introduction

In this page you can find the example usage for javax.print StreamPrintServiceFactory getPrintService.

Prototype

public abstract StreamPrintService getPrintService(OutputStream out);

Source Link

Document

Returns a StreamPrintService that can print to the specified output stream.

Usage

From source file:JuliaSet3.java

public void save() throws IOException {
    // Find a factory object for printing Printable objects to PostScript.
    DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
    String format = "application/postscript";
    StreamPrintServiceFactory factory = StreamPrintServiceFactory.lookupStreamPrintServiceFactories(flavor,
            format)[0];/*from  w  w  w  .jav a 2s .c  om*/

    // Ask the user to select a file and open the selected file
    JFileChooser chooser = new JFileChooser();
    if (chooser.showSaveDialog(this) != 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(service, null);

    // And close the output file.
    out.close();
}