Refine search
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); aset.add(MediaSizeName.ISO_A4); aset.add(new PrinterResolution(300, 300, PrinterResolution.DPI)); aset.add(new MediaPrintableArea(2, 2, 210 - 4, 297 - 4, MediaPrintableArea.MM)); PrinterJob pj = PrinterJob.getPrinterJob(); pj.setPrintable(new PrintTask()); if (pj.printDialog(aset)) { try { pj.print(aset); } catch (PrinterException ex) { ex.printStackTrace(); } }
public CurrentJob(int id,PrinterJob job,PrintRequestAttributeSet a,String name,int count) { this.id=id; att=new HashPrintRequestAttributeSet(); att.addAll(a); this.job=job; this.job.setJobName(name); pages=new Page[count]; }
/** * Prints using custom PrintRequestAttribute values. */ private static void printWithAttributes(PDDocument document) throws IOException, PrinterException { PrinterJob job = PrinterJob.getPrinterJob(); job.setPageable(new PDFPageable(document)); PrintRequestAttributeSet attr = new HashPrintRequestAttributeSet(); attr.add(new PageRanges(1, 1)); // pages 1 to 1 job.print(attr); }
FileOutputStream output; StreamPrintServiceFactory[] factories = PrinterJob .lookupStreamPrintServices(psMimeType); if (factories.length == 0) { throw new IOException("Couldn't find print service"); StreamPrintService psPrinter = factories[0].getPrintService(output); PrinterJob pjob = PrinterJob.getPrinterJob(); pjob.setPrintService(psPrinter); // if app wants to specify this printer. PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); aset.add(new Copies(2));
PrinterJob printerJob = PrinterJob.getPrinterJob(); printerJob.setPrintable(this); printerJob.setPrintService(printService); if(displayPrintDialogOnlyOnce || displayPageDialogOnlyOnce) printRequestAttributeSet = new HashPrintRequestAttributeSet(); setDefaultPrintRequestAttributeSet(printRequestAttributeSet); setOrientation((JasperPrint)jasperPrintList.get(0), printRequestAttributeSet); (!displayPrintDialogOnlyOnce && !displayPageDialogOnlyOnce)) printRequestAttributeSet = new HashPrintRequestAttributeSet(); setDefaultPrintRequestAttributeSet(printRequestAttributeSet); setOrientation(jasperPrint, printRequestAttributeSet); printRequestAttributeSet.add(new PageRanges(startPageIndex + 1, endPageIndex + 1));
public static void PDFPrintingServices(String filePath) throws IOException, PrinterException { PrintRequestAttributeSet attr_set = new HashPrintRequestAttributeSet(); attr_set.add(MediaSizeName.ISO_A4); attr_set.add(Sides.ONE_SIDED); PDDocument pdf = PDDocument.load(new File(filePath)); PDFPageable p = new PDFPageable(pdf); PDFPrintable printable = new PDFPrintable(pdf, Scaling.SCALE_TO_FIT); PrinterJob job = PrinterJob.getPrinterJob(); job.setJobName("My Printer"); job.setPageable(p); job.setPrintable(printable); if(job.printDialog()) { job.print(); job.print(attr_set); } }
PageFormat pf = job.defaultPage(); Paper p = pf.getPaper(); p.setSize(UnitConv.mm2pt(62), UnitConv.mm2pt(40)); PrintRequestAttributeSet printReqAttrs = new HashPrintRequestAttributeSet(); PrintRequestAttribute jobPrinArea = new MediaPrintableArea(0, 0, 64, 40, MediaPrintableArea.MM); printReqAttrs.add(jobPrinArea); if (job.printDialog(printReqAttrs)) { try { job.setPrintable(myPrintable, pf); job.setPrintService(printService);
File file = new File("path/to/pdf"); DocFlavor flavor = DocFlavor.INPUT_STREAM.PDF; PrintRequestAttributeSet attr = new HashPrintRequestAttributeSet(); attr.add(MediaSizeName.ISO_A4); FileInputStream fis = new FileInputStream(file); Doc doc = new SimpleDoc(fis, flavor, null); DocPrintJob job = printService.createPrintJob(); job.print(doc, attr); fis.close();
this.printService = PrinterJob.lookupPrintServices(); PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); aset.add(new PageRanges(1, 1)); aset.add(new Copies(1)); PrinterJob printJob = PrinterJob.getPrinterJob(); printJob.setPrintable(this);
printDialogButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { final PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet(); attributes.add(DialogTypeSelection.NATIVE); attributes.add(new sun.print.DialogOwner(TestPrintDialog.this)); PrinterJob printJob = PrinterJob.getPrinterJob(); printJob.printDialog(attributes);
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); aset.add(new Copies(5)); aset.add(MediaSize.ISO_A4); aset.add(Sides.DUPLEX);
PrinterJob printJob = PrinterJob.getPrinterJob(); PageFormat pageFormat = PrinterJob.getPrinterJob().defaultPage(); printJob.setJobName(jobName); Book book = new Book(); printJob.setPageable(book); Paper paper = new Paper(); printJob.setPrintService(p); PrintRequestAttributeSet attr_set = new HashPrintRequestAttributeSet(); attr_set.add(MediaSizeName.ISO_A6); printJob.print(attr_set);
PrinterJob job = PrinterJob.getPrinterJob(); int selectedService = 0; selectedService = 0; PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet(); printRequestAttributeSet.add(OrientationRequested.PORTRAIT); printRequestAttributeSet.add(MediaSizeName.ISO_A0); MediaSizeName mediaSizeName = MediaSize.findMedia(64,25,MediaPrintableArea.MM); printRequestAttributeSet.add(mediaSizeName); printRequestAttributeSet.add(new Copies(1)); JRPrintServiceExporter exporter; exporter = new JRPrintServiceExporter(); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasper_print); exporter.setParameter(JRPrintServiceExporterParameter.PRINT_REQUEST_ATTRIBUTE_SET, printRequestAttributeSet); exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG, Boolean.FALSE); exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, Boolean.TRUE); exporter.exportReport(); job.print(printRequestAttributeSet);
PrinterJob pj = PrinterJob.getPrinterJob(); // Create an Attribute set PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); // A different way to bring Up Native Dialog from Java aset.add(sun.print.DialogTypeSelection.NATIVE); // Looks like this class is being moved to javax.print.attribute.standard for Java 7 // To Remove the Icon from the dialog provide an owner. Frame f = Frame(); aset.add(new sun.print.DialogOwner(f)); pj.printDialog(aset); // The dialog should not have an icon now.
private static PrinterJob getPrintJob(String jobName) job = PrinterJob.getPrinterJob(); format = new HashPrintRequestAttributeSet(); format.add(Chromaticity.COLOR); else format.add(Chromaticity.MONOCHROME); format.add(new JobName(jobName, null));
/** * Asks the user for a printer and settings and return the pageformat.<br> * Does not print! Use {@link #printJob(java.awt.print.PrinterJob, javax.print.attribute.PrintRequestAttributeSet, boolean)} to print. * * @param job is the new printerjob * @param jobName is the jobname, null = none * @param aset is an initialized (and possibly empty) attribute set, must not be null, because its returned! * @return the pageformat and possibly updated aset, null if printing aborted */ public static PageFormat print(PrinterJob job, String jobName, PrintRequestAttributeSet aset) { if (aset.get(Media.class) == null) { aset.add(mediaSizeName); } if (aset.get(MediaPrintableArea.class) == null) { aset.add(area); } if (jobName != null) { aset.add(new JobName(jobName, Locale.getDefault())); job.setJobName(jobName); } if (job.printDialog(aset)) { return getPageFormat(aset); } return null; }
printerJob.defaultPage(pageFormat); printerJob.setPrintService(printService[selectedService]); PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet(); printRequestAttributeSet.add(MediaSizeName.NA_LETTER); printRequestAttributeSet.add(new Copies(1));
// 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 pras = new HashPrintRequestAttributeSet(); DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE; PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); aset.add(MediaSizeName.ISO_A4); aset.add(new Copies(1)); aset.add(Sides.ONE_SIDED); aset.add(Finishings.STAPLE); for (PDDocument doc : docs) { PrinterJob printJob = PrinterJob.getPrinterJob(); printJob.setPrintService(service); doc.silentPrint(printJob);
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet(); pras.add(new Copies(1)); job.print(doc, pras); pjw.waitForDone(); is.close(); job.addPrintJobListener(new PrintJobAdapter() { public void printJobCanceled(PrintJobEvent pje) { allDone();