public Print2DPrinterJob() {

                /* Construct the print request specification.
                * The print data is a Printable object.
                * the request additonally specifies a job name, 2 copies, and
                * landscape orientation of the media.
                */
                PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
                aset.add(OrientationRequested.LANDSCAPE);
                aset.add(new Copies(2));
                aset.add(new JobName("My job", null));

                /* Create a print job */
                PrinterJob pj = PrinterJob.getPrinterJob();       
                pj.setPrintable(this);
                /* locate a print service that can handle the request */
                PrintService[] services =
                        PrinterJob.lookupPrintServices();

                if (services.length > 0) {
                        System.out.println("selected printer " + services[0].getName());
                        try {
                                pj.setPrintService(services[0]);
                                pj.pageDialog(aset);
                                if(pj.printDialog(aset)) {
                                        pj.print(aset);
                                }
                        } catch (PrinterException pe) { 
                                System.err.println(pe);
                        }
                }
        }
Beispiel #2
0
 // {{{ pageSetup() method
 public static void pageSetup(View view) {
   PrinterJob prnJob = getPrintJob("PageSetupOnly");
   if (prnJob.pageDialog(format) != null) savePrintSpec();
 } // }}}
 /**
  * Richtet die Seite ein
  *
  * @return true, if successful
  */
 public boolean setupPageFormat() {
   PageFormat defaultPF = pjob.defaultPage();
   this.pageformat = pjob.pageDialog(defaultPF);
   pjob.setPrintable(this, this.pageformat);
   return (this.pageformat != defaultPF);
 }