Example usage for javax.print SimpleDoc SimpleDoc

List of usage examples for javax.print SimpleDoc SimpleDoc

Introduction

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

Prototype

public SimpleDoc(Object printData, DocFlavor flavor, DocAttributeSet attributes) 

Source Link

Document

Constructs a SimpleDoc with the specified print data, doc flavor and doc attribute set.

Usage

From source file:ImagePrint.java

public static void main(String[] args) throws Exception {
    PrintService service = PrintServiceLookup.lookupDefaultPrintService();
    DocPrintJob job = service.createPrintJob();
    DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
    SimpleDoc doc = new SimpleDoc(new MyPrintable(), flavor, null);
    job.print(doc, null);//  w  ww.  ja  v  a  2  s  . c om
}

From source file:Main.java

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

    DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF;
    PrintService service = PrintServiceLookup.lookupDefaultPrintService();

    DocPrintJob job = service.createPrintJob();
    Doc doc = new SimpleDoc(is, flavor, null);

    PrintJobWatcher pjDone = new PrintJobWatcher(job);

    job.print(doc, null);//ww  w.j  a  v a2s.c om

    pjDone.waitForDone();

    is.close();
}

From source file:Main.java

static public void main(String args[]) throws Exception {
    PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
    pras.add(new Copies(1));

    PrintService pss[] = PrintServiceLookup.lookupPrintServices(DocFlavor.INPUT_STREAM.GIF, pras);

    if (pss.length == 0)
        throw new RuntimeException("No printer services available.");

    PrintService ps = pss[0];/*www .j  a v a 2 s . c o  m*/
    System.out.println("Printing to " + ps);

    DocPrintJob job = ps.createPrintJob();

    FileInputStream fin = new FileInputStream("YOurImageFileName.PNG");
    Doc doc = new SimpleDoc(fin, DocFlavor.INPUT_STREAM.GIF, null);

    job.print(doc, pras);

    fin.close();
}

From source file:PrintImage.java

static public void main(String args[]) throws Exception {
    PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
    pras.add(new Copies(1));
    PrintService pss[] = PrintServiceLookup.lookupPrintServices(DocFlavor.INPUT_STREAM.GIF, pras);
    if (pss.length == 0)
        throw new RuntimeException("No printer services available.");
    PrintService ps = pss[0];/*from   ww w  . j a v  a  2  s.  c  o m*/
    System.out.println("Printing to " + ps);
    DocPrintJob job = ps.createPrintJob();
    FileInputStream fin = new FileInputStream("YOurImageFileName.PNG");
    Doc doc = new SimpleDoc(fin, DocFlavor.INPUT_STREAM.GIF, null);
    job.print(doc, pras);
    fin.close();
}

From source file:PrintImage.java

static public void main(String args[]) throws Exception {
    try {//from   w  w w.  jav a  2 s.  c  o m
        PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
        pras.add(new Copies(1));

        PrintService pss[] = PrintServiceLookup.lookupPrintServices(DocFlavor.INPUT_STREAM.GIF, pras);

        if (pss.length == 0)
            throw new RuntimeException("No printer services available.");

        PrintService ps = pss[0];
        System.out.println("Printing to " + ps);

        DocPrintJob job = ps.createPrintJob();

        FileInputStream fin = new FileInputStream("YOurImageFileName.PNG");
        Doc doc = new SimpleDoc(fin, DocFlavor.INPUT_STREAM.GIF, null);

        job.print(doc, pras);

        fin.close();
    } catch (IOException ie) {
        ie.printStackTrace();
    } catch (PrintException pe) {
        pe.printStackTrace();
    }
}

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);//w  ww .j a va 2s  .  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);//from  w w w. ja  va2s. c  om

    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.ja  va 2 s  . co  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   w  w  w .j  ava  2 s  . c o  m*/
            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   ww  w.ja  va 2  s  .  co  m*/
        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");
        }
    }
}