javax.print.ServiceUI Java Examples
The following examples show how to use
javax.print.ServiceUI.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ServiceDlgPageRangeTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * Starts the application. */ public static void printTest() { System.out.println("\nDefault print service: " + PrintServiceLookup.lookupDefaultPrintService()); System.out.println("is flavor: "+flavor+" supported? "+ services[0].isDocFlavorSupported(flavor)); System.out.println("is Page Ranges category supported? "+ services[0].isAttributeCategorySupported(PageRanges.class)); System.out.println("is PageRanges[2] value supported ? "+ services[0].isAttributeValueSupported( new PageRanges(2), flavor, null)); HashPrintRequestAttributeSet prSet = new HashPrintRequestAttributeSet(); //prSet.add(new PageRanges(2)); PrintService selService = ServiceUI.printDialog(null, 200, 200, services, services[0], flavor, prSet); System.out.println("\nSelected Values\n"); Attribute attr[] = prSet.toArray(); for (int x = 0; x < attr.length; x ++) { System.out.println("Attribute: " + attr[x].getName() + " Value: " + attr[x]); } }
Example #2
Source File: PrintImageOutput.java From RipplePower with Apache License 2.0 | 6 votes |
public static boolean out(BufferedImage image) { try { DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE; PrintRequestAttributeSet requestAttributeSet = new HashPrintRequestAttributeSet(); requestAttributeSet.add(MediaSizeName.ISO_A4); requestAttributeSet.add(new JobName(LSystem.applicationName + LSystem.getTime(), Locale.ENGLISH)); PrintService[] services = PrintServiceLookup.lookupPrintServices(flavor, requestAttributeSet); PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService(); PrintService service = ServiceUI.printDialog(null, 100, 100, services, defaultService, flavor, requestAttributeSet); if (service != null) { DocPrintJob job = service.createPrintJob(); SimpleDoc doc = new SimpleDoc(new BufferedImagePrintable(image), flavor, null); job.print(doc, requestAttributeSet); } } catch (Exception e) { return false; } return true; }
Example #3
Source File: PrintUtils.java From osp with GNU General Public License v3.0 | 6 votes |
public static void printComponent(Component c) { // 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(OrientationRequested.PORTRAIT); // PORTRAIT mode printAttributes.add(Chromaticity.MONOCHROME); // print in mono printAttributes.add(javax.print.attribute.standard.PrintQuality.HIGH); // highest resolution // 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; } // Now call a method defined below to finish the printing printToService(c, service, printAttributes); }
Example #4
Source File: ServiceDlgSheetCollateTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private static void printTest() { ServiceDlgSheetCollateTest pd = new ServiceDlgSheetCollateTest(); DocFlavor flavor = DocFlavor.INPUT_STREAM.JPEG; //DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE; PrintService defService = null, service[] = null; defService = PrintServiceLookup.lookupDefaultPrintService(); service = PrintServiceLookup.lookupPrintServices(flavor, null); if ((service == null) || (service.length == 0)) { throw new RuntimeException("No Printer services found"); } if (defService != null) { System.out.println("\nDefault print service: " + service ); System.out.println("is flavor: "+flavor+" supported? "+ defService.isDocFlavorSupported(flavor)); System.out.println("is SheetCollate category supported? "+ defService.isAttributeCategorySupported(SheetCollate.class)); System.out.println("is SheetCollate.COLLATED value supported ? "+ defService.isAttributeValueSupported(SheetCollate.COLLATED, flavor, null)); } HashPrintRequestAttributeSet prSet = new HashPrintRequestAttributeSet(); try { PrintService selService = ServiceUI.printDialog(null, 200, 200, service, defService, flavor, prSet); } catch (IllegalArgumentException ia) { System.out.println("Exception thrown : " + ia); } System.out.println("\nSelected Values\n"); Attribute attr[] = prSet.toArray(); for (int x = 0; x < attr.length; x ++) { System.out.println("Attribute: " + attr[x].getName() + " Value: " + attr[x]); } }
Example #5
Source File: ServiceDialogValidateTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private static void printTest() { PrintService defService = null, service[] = null; HashPrintRequestAttributeSet prSet = new HashPrintRequestAttributeSet(); DocFlavor flavor = DocFlavor.INPUT_STREAM.JPEG; service = PrintServiceLookup.lookupPrintServices(flavor, null); defService = PrintServiceLookup.lookupDefaultPrintService(); if ((service == null) || (service.length == 0)) { throw new RuntimeException("No Printer services found"); } File f = new File("output.ps"); Destination d = new Destination(f.toURI()); prSet.add(d); if (defService != null) { System.out.println("isAttrCategory Supported? " + defService.isAttributeCategorySupported(Destination.class)); System.out.println("isAttrValue Supported? " + defService.isAttributeValueSupported(d, flavor, null)); } defService = ServiceUI.printDialog(null, 100, 100, service, defService, flavor, prSet); ServiceUI.printDialog(null, 100, 100, service, defService, DocFlavor.SERVICE_FORMATTED.PAGEABLE, new HashPrintRequestAttributeSet()); }
Example #6
Source File: Java14PrintUtil.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
public static boolean print( final MasterReport report, final ReportProgressListener progressListener ) throws PrintException, ReportProcessingException { final PrintService[] services = PrintServiceLookup.lookupPrintServices( DocFlavor.SERVICE_FORMATTED.PAGEABLE, null ); 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; }