Example usage for javax.print StreamPrintService createPrintJob

List of usage examples for javax.print StreamPrintService createPrintJob

Introduction

In this page you can find the example usage for javax.print StreamPrintService createPrintJob.

Prototype

public DocPrintJob createPrintJob();

Source Link

Document

Creates and returns a PrintJob capable of handling data from any of the supported document flavors.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    OutputStream fos = new BufferedOutputStream(new FileOutputStream("filename.ps"));
    DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF;
    StreamPrintServiceFactory[] factories = StreamPrintServiceFactory.lookupStreamPrintServiceFactories(flavor,
            DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType());

    StreamPrintService service = factories[0].getPrintService(fos);

    DocPrintJob job = service.createPrintJob();
    PrintJobAttributeSet set = new HashPrintJobAttributeSet(job.getAttributes());
    set.add(new JobMediaSheetsCompleted(0));
    job.addPrintJobAttributeListener(new MyPrintJobAttributeListener(), set);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    OutputStream fos = new BufferedOutputStream(new FileOutputStream("filename.ps"));
    DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF;
    StreamPrintServiceFactory[] factories = StreamPrintServiceFactory.lookupStreamPrintServiceFactories(flavor,
            DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType());

    StreamPrintService service = factories[0].getPrintService(fos);

    DocPrintJob job = service.createPrintJob();
    job.addPrintJobListener(new MyPrintJobListener());
}

From source file:StreamOneFour.java

public static void main(String args[]) throws Exception {
    String infile = "StreamOneFour.java";
    DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF;
    String mimeType = DocFlavor.INPUT_STREAM.POSTSCRIPT.getMimeType();
    StreamPrintServiceFactory[] factories = StreamPrintServiceFactory.lookupStreamPrintServiceFactories(flavor,
            mimeType);//from  w w w  .j  a  va 2 s . c o  m
    String filename = "out.ps";
    FileOutputStream fos = new FileOutputStream(filename);
    StreamPrintService sps = factories[0].getPrintService(fos);

    FileInputStream fis = new FileInputStream(infile);
    DocPrintJob dpj = sps.createPrintJob();
    PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
    Doc doc = new SimpleDoc(fis, flavor, null);
    dpj.print(doc, pras);
    fos.close();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    OutputStream fos = new BufferedOutputStream(new FileOutputStream("filename.ps"));

    DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF;
    InputStream is = new BufferedInputStream(new FileInputStream("filename.gif"));
    StreamPrintServiceFactory[] factories = StreamPrintServiceFactory.lookupStreamPrintServiceFactories(flavor,
            DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType());

    StreamPrintService service = factories[0].getPrintService(fos);
    DocPrintJob job = service.createPrintJob();
    Doc doc = new SimpleDoc(is, flavor, null);

    PrintJobWatcher pjDone = new PrintJobWatcher(job);

    job.print(doc, null);/*w  w w . j a  v  a 2s.co m*/

    pjDone.waitForDone();

    is.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    InputStream is = new BufferedInputStream(new FileInputStream("filename.gif"));

    OutputStream fos = new BufferedOutputStream(new FileOutputStream("filename.ps"));

    DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF;
    StreamPrintServiceFactory[] factories = StreamPrintServiceFactory.lookupStreamPrintServiceFactories(flavor,
            DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType());

    if (factories.length > 0) {
        StreamPrintService service = factories[0].getPrintService(fos);
        DocPrintJob job = service.createPrintJob();
        Doc doc = new SimpleDoc(is, flavor, null);

        PrintJobWatcher pjDone = new PrintJobWatcher(job);

        job.print(doc, null);/*from   w  w  w  .  j a  v  a2  s.c o m*/

        pjDone.waitForDone();
    }

    is.close();
    fos.close();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    OutputStream fos = new BufferedOutputStream(new FileOutputStream("filename.ps"));
    DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF;
    InputStream is = new BufferedInputStream(new FileInputStream("filename.gif"));
    StreamPrintServiceFactory[] factories = StreamPrintServiceFactory.lookupStreamPrintServiceFactories(flavor,
            DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType());

    StreamPrintService service = factories[0].getPrintService(fos);
    final DocPrintJob job = service.createPrintJob();
    Doc doc = new SimpleDoc(is, flavor, null);

    PrintJobWatcher pjDone = new PrintJobWatcher(job);

    if (job instanceof CancelablePrintJob) {
        CancelablePrintJob cancelJob = (CancelablePrintJob) job;
        try {/*from   www  .  ja  v  a2  s  .  com*/
            cancelJob.cancel();
        } catch (PrintException e) {
        }
    }
    job.print(doc, null);
    pjDone.waitForDone();
    is.close();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    try {//from  w  w w .j  a  v a  2s  .  c om
        OutputStream fos = new BufferedOutputStream(new FileOutputStream("filename.ps"));
        DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF;
        InputStream is = new BufferedInputStream(new FileInputStream("filename.gif"));
        StreamPrintServiceFactory[] factories = StreamPrintServiceFactory
                .lookupStreamPrintServiceFactories(flavor, DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType());

        StreamPrintService service = factories[0].getPrintService(fos);
        final DocPrintJob job = service.createPrintJob();
        Doc doc = new SimpleDoc(is, flavor, null);

        PrintJobWatcher pjDone = new PrintJobWatcher(job);

        if (job instanceof CancelablePrintJob) {
            CancelablePrintJob cancelJob = (CancelablePrintJob) job;
            try {
                cancelJob.cancel();
            } catch (PrintException e) {
            }
        }
        job.print(doc, null);
        pjDone.waitForDone();
        is.close();
    } catch (PrintException e) {
        if (e.getCause() instanceof PrinterAbortException) {
            System.out.println("Print job was cancelled");
        }
    }
}