// get default service PrintService service = PrintServiceLookup.lookupDefaultPrintService(); // this is your old awt job, which you can use to get default pageFormat PrinterJob job = PrinterJob.getPrinterJob(); // set your printer service to old awt so that you can get the default paper job.setPrintService(service); // get the default page format from the printer you selected PageFormat pageFormat = job.getPageFormat(null); // do some paper stuff etc. here // get your doc DocPrintJob printJob = service.createPrintJob(); Book book = new Book(); // Print interface implements printable book.append(new PrintInterface(), pageFormat); // make your attr here PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); aset.add(PrintQuality.HIGH); // Create your doc for pageable SimpleDoc doc = new SimpleDoc(book, DocFlavor.SERVICE_FORMATTED.PAGEABLE, null); /// and voila, print it printJob.print(doc, aset);
PrintRequestAttributeSet aset = createAsetForMedia(size); PrinterJob pj = PrinterJob.getPrinterJob(); PageFormat pageFormat = pj.getPageFormat(aset); pj.setPrintable(this, pageFormat); if (pj.printDialog()) {
public void print(PrinterJob printerJob) throws PrinterException { HashPrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet(); Media[] res = (Media[]) printerJob.getPrintService().getSupportedAttributeValues(Media.class, null, null); for (int i = 0; i < res.length; i++) { System.out.println("res[" + i + "]=" + res[i]); System.out.println(res[i].toString()); if (res[i].toString().equals(printerMedia)) { attributes.add(res[i]); } } printerJob.print(attributes); PageFormat pageFormat = printerJob.getPageFormat(attributes); System.out.println("[after opening]"); printPageFormat(pageFormat); pageFormat.setOrientation(PageFormat.PORTRAIT); printerJob.setPrintable(new TestSequenceInstanceLabel.MyPrintable(this), pageFormat); try { printerJob.print(); } catch (PrinterException ex) { ex.printStackTrace(); } }
PageFormat pf =job.getPageFormat(tattr); if (pf.getImageableWidth()<=0) { log.warning("PageFormat is invalid - using default attributes"); pf=job.getPageFormat(att); if (pf.getImageableWidth()<=0) { log.warning("PageFormat is invalid - using default page"); pf=job.getPageFormat(null);
pj.setPrintable(this); PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); PageFormat pf = pj.getPageFormat(aset); Paper paper = pf.getPaper();
PageFormat pageFormat = pj.getPageFormat(aset); Paper paper = pageFormat.getPaper(); double margin = 12;
PageFormat pf =job.getPageFormat(att); if (pf.getImageableWidth()<=0) { pf=job.getPageFormat(null);