Example usage for javax.print.attribute HashPrintRequestAttributeSet HashPrintRequestAttributeSet

List of usage examples for javax.print.attribute HashPrintRequestAttributeSet HashPrintRequestAttributeSet

Introduction

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

Prototype

public HashPrintRequestAttributeSet() 

Source Link

Document

Construct a new, empty print request attribute set.

Usage

From source file:Main.java

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

    // Set up the attribute set
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    aset.add(new Copies(2));

}

From source file:Main.java

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

    // Set up destination attribute
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    aset.add(new Destination(new java.net.URI("file:e:/temp/out.ps")));

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    // Set up the attribute set
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    aset.add(OrientationRequested.PORTRAIT);
    // aset.add(OrientationRequested.LANDSCAPE);

}

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];/*  www .ja  v a  2  s . co  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  ww w  .  j  av  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:OneFourDialog.java

public static void main(String args[]) throws Exception {
    String filename = args[0];/*from   ww  w.ja v  a  2  s  .c o m*/
    PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
    DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF;
    PrintService printService[] = PrintServiceLookup.lookupPrintServices(flavor, pras);
    PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
    PrintService service = ServiceUI.printDialog(null, 200, 200, printService, defaultService,
            DocFlavor.INPUT_STREAM.GIF, pras);
    if (service != null) {
        DocPrintJob job = service.createPrintJob();
        PrintJobListener listener = new PrintJobAdapter() {
            public void printDataTransferCompleted(PrintJobEvent e) {
                System.exit(0);
            }
        };
        job.addPrintJobListener(listener);
        FileInputStream fis = new FileInputStream(filename);
        DocAttributeSet das = new HashDocAttributeSet();
        Doc doc = new SimpleDoc(fis, flavor, das);
        job.print(doc, pras);
        Thread.sleep(10000);
    }
}

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   www  .  j a  v  a2  s  . co  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 args[]) throws Exception {
    String filename = args[0];//from  w w  w.j a  va 2  s.c  om
    DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF;
    PrintService printService = PrintServiceLookup.lookupDefaultPrintService();
    DocPrintJob job = printService.createPrintJob();
    PrintJobListener listener = new PrintJobAdapter() {
        public void printDataTransferCompleted(PrintJobEvent e) {
            System.out.println("Good-bye");
            System.exit(0);
        }
    };
    job.addPrintJobListener(listener);
    PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
    FileInputStream fis = new FileInputStream(filename);
    DocAttributeSet das = new HashDocAttributeSet();
    Doc doc = new SimpleDoc(fis, flavor, das);
    job.print(doc, pras);
    Thread.sleep(10000);
}

From source file:TablePrintLastVersion.java

public static void main(String args[]) {
    final Object rows[][] = { { "one", "1" }, { "two", "2" }, { "three", "3" }, { "four", "4" }, { "one", "1" },
            { "two", "2" }, { "three", "3" }, { "four", "4" }, { "one", "1" }, { "two", "2" }, { "three", "3" },
            { "four", "4" }, { "one", "1" }, { "two", "2" }, { "three", "3" }, { "four", "4" },

    };//from   w ww .java 2 s  .  c  o  m
    final Object headers[] = { "English", "#" };

    JFrame frame = new JFrame("Table Printing");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    final JTable table = new JTable(rows, headers);
    JScrollPane scrollPane = new JScrollPane(table);
    frame.add(scrollPane, BorderLayout.CENTER);
    JButton button = new JButton("Print");
    ActionListener printAction = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                MessageFormat headerFormat = new MessageFormat("Page {0}");
                MessageFormat footerFormat = new MessageFormat("- {0} -");
                table.print(JTable.PrintMode.NORMAL, headerFormat, footerFormat, true,
                        new HashPrintRequestAttributeSet(), true);

            } catch (PrinterException pe) {
                System.err.println("Error printing: " + pe.getMessage());
            }
        }
    };
    button.addActionListener(printAction);
    frame.add(button, BorderLayout.SOUTH);
    frame.setSize(300, 150);
    frame.setVisible(true);
}