List of usage examples for javax.print ServiceUI printDialog
@SuppressWarnings("deprecation") public static PrintService printDialog(GraphicsConfiguration gc, int x, int y, PrintService[] services, PrintService defaultService, DocFlavor flavor, PrintRequestAttributeSet attributes) throws HeadlessException
From source file:OneFourDialog.java
public static void main(String args[]) throws Exception { String filename = args[0];/*from w ww . j a 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:JuliaSet3.java
public void print() { // Get a list of all printers that can handle Printable objects. DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE; PrintService[] services = PrintServiceLookup.lookupPrintServices(flavor, null); // Set some define printing attributes PrintRequestAttributeSet printAttributes = new HashPrintRequestAttributeSet(); printAttributes.add(OrientationRequested.LANDSCAPE); // landscape mode printAttributes.add(Chromaticity.MONOCHROME); // print in mono // Display a dialog that allows the user to select one of the // available printers and to edit the default attributes PrintService service = ServiceUI.printDialog(null, 100, 100, services, null, null, printAttributes); // If the user canceled, don't do anything if (service == null) return;/*from w w w. j a v a 2s .c om*/ // Now call a method defined below to finish the printing printToService(service, printAttributes); }
From source file:org.pentaho.reporting.engine.classic.extensions.modules.java14print.Java14PrintUtil.java
public static boolean print(final MasterReport report, final ReportProgressListener progressListener) throws PrintException, ReportProcessingException { final PrintService[] services = PrintServiceLookup.lookupPrintServices(DocFlavor.SERVICE_FORMATTED.PAGEABLE, null);/*from w w w .j ava 2s .c o m*/ if (services.length == 0) { throw new PrintException("Unable to find a matching print service implementation."); } PrintRequestAttributeSet attributes = Java14PrintUtil.copyConfiguration(null, report); attributes = Java14PrintUtil.copyAuxillaryAttributes(attributes, report); final PrintService service = ServiceUI.printDialog(null, 50, 50, services, lookupPrintService(), DocFlavor.SERVICE_FORMATTED.PAGEABLE, attributes); if (service == null) { return false; } final PrintReportProcessor reportPane = new PrintReportProcessor(report); if (progressListener != null) { reportPane.addReportProgressListener(progressListener); } try { reportPane.fireProcessingStarted(); final DocPrintJob job = service.createPrintJob(); final SimpleDoc document = new SimpleDoc(reportPane, DocFlavor.SERVICE_FORMATTED.PAGEABLE, null); job.print(document, attributes); } finally { reportPane.fireProcessingFinished(); reportPane.close(); if (progressListener != null) { reportPane.removeReportProgressListener(progressListener); } } return true; }