当前位置: 首页>>代码示例>>Java>>正文


Java PrintServiceLookup.lookupPrintServices方法代码示例

本文整理汇总了Java中javax.print.PrintServiceLookup.lookupPrintServices方法的典型用法代码示例。如果您正苦于以下问题:Java PrintServiceLookup.lookupPrintServices方法的具体用法?Java PrintServiceLookup.lookupPrintServices怎么用?Java PrintServiceLookup.lookupPrintServices使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.print.PrintServiceLookup的用法示例。


在下文中一共展示了PrintServiceLookup.lookupPrintServices方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: lookupDefaultPrintService

import javax.print.PrintServiceLookup; //导入方法依赖的package包/类
protected static PrintService lookupDefaultPrintService() {
    PrintService service = PrintServiceLookup.lookupDefaultPrintService();

    /* Pageable implies Printable so checking both isn't strictly needed */
    if (service != null &&
        service.isDocFlavorSupported(
                            DocFlavor.SERVICE_FORMATTED.PAGEABLE) &&
        service.isDocFlavorSupported(
                            DocFlavor.SERVICE_FORMATTED.PRINTABLE)) {
        return service;
    } else {
       PrintService []services =
         PrintServiceLookup.lookupPrintServices(
                            DocFlavor.SERVICE_FORMATTED.PAGEABLE, null);
       if (services.length > 0) {
           return services[0];
       }
    }
    return null;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:21,代码来源:RasterPrinterJob.java

示例2: main

import javax.print.PrintServiceLookup; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    for (PrintService service : PrintServiceLookup.lookupPrintServices(null, null)) {
        String serviceName = service.getName();
        PrinterName name = service.getAttribute(PrinterName.class);
        String printerName = name.getValue();

        PrintService serviceByName = lookupByName(printerName);
        System.out.println("service " + service);
        System.out.println("serviceByName " + serviceByName);
        if (!service.equals(serviceByName)) {
            throw new RuntimeException("NOK " + serviceName
                               + " expected: " + service.getClass().getName()
                               + " got: " + serviceByName.getClass().getName());
        }
    }
    System.out.println("Test PASSED");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:GetPrintServices.java

示例3: main

import javax.print.PrintServiceLookup; //导入方法依赖的package包/类
/**
 * Starts the application.
 */
public static void main(java.lang.String[] args) throws Exception {
    services = PrintServiceLookup.lookupPrintServices(flavor,  null);

    if (services.length == 0) {
        System.out.println("No print service found!!");
        return;
    }
    SwingUtilities.invokeAndWait(() -> {
        doTest(ServiceDlgPageRangeTest::printTest);
    });
    mainThread = Thread.currentThread();
    try {
        Thread.sleep(600000);
    } catch (InterruptedException e) {
        if (!testPassed && testGeneratedInterrupt) {
            throw new RuntimeException("PageRanges option is not disabled "
                    + "for for Non serv-formatted flvrs");
        }
    }
    if (!testGeneratedInterrupt) {
        throw new RuntimeException("user has not executed the test");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:ServiceDlgPageRangeTest.java

示例4: getPrintService

import javax.print.PrintServiceLookup; //导入方法依赖的package包/类
public static PrintService getPrintService(String printername) {
    
    // Initalize print service
    
    if (printername == null) {
        return PrintServiceLookup.lookupDefaultPrintService();       
    } else {
        
        if ("(Show dialog)".equals(printername)) {
            return null; // null means "you have to show the print dialog"
        } else if ("(Default)".equals(printername)) {
            return PrintServiceLookup.lookupDefaultPrintService(); 
        } else {
            PrintService[] pservices = 
                    PrintServiceLookup.lookupPrintServices(DocFlavor.SERVICE_FORMATTED.PRINTABLE , null);
            for (PrintService s : pservices) {    
                if (printername.equals(s.getName())) {
                    return s;
                }
            }
            return PrintServiceLookup.lookupDefaultPrintService();       
        }                
    }                 
}
 
开发者ID:iMartinezMateu,项目名称:openbravo-pos,代码行数:25,代码来源:ReportUtils.java

示例5: getPrintService

import javax.print.PrintServiceLookup; //导入方法依赖的package包/类
/**
 *
 * @param printername
 * @return
 */
public static PrintService getPrintService(String printername) {
    
    // Initalize print service
    
    if (printername == null) {
        return PrintServiceLookup.lookupDefaultPrintService();       
    } else {
        
        if ("(Show dialog)".equals(printername)) {
            return null; // null means "you have to show the print dialog"
        } else if ("(Default)".equals(printername)) {
            return PrintServiceLookup.lookupDefaultPrintService(); 
        } else {
            PrintService[] pservices = 
                    PrintServiceLookup.lookupPrintServices(DocFlavor.SERVICE_FORMATTED.PRINTABLE , null);
            for (PrintService s : pservices) {    
                if (printername.equals(s.getName())) {
                    return s;
                }
            }
            return PrintServiceLookup.lookupDefaultPrintService();       
        }                
    }                 
}
 
开发者ID:sbandur84,项目名称:micro-Blagajna,代码行数:30,代码来源:ReportUtils.java

示例6: getDefaultPrinterNameFromIni

import javax.print.PrintServiceLookup; //导入方法依赖的package包/类
private String getDefaultPrinterNameFromIni(final String propName)
{
	log.debug("Looking for " + propName + " in ini file");

	String printerName = Ini.getProperty(propName);
	if (!Check.isEmpty(printerName))
	{
		log.debug("Found printerName: " + printerName);
		return printerName;
	}

	log.debug("Looking for machine's printers");
	final PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);
	if (services == null || services.length == 0)
	{
		// [email protected]: so what? we don't need a printer to generate PDFs
		// log.warn("No default printer found on this machine");
		return "";
	}

	printerName = services[0].getName();
	Ini.setProperty(propName, printerName);
	log.debug("Found printerName: " + printerName);
	return printerName;
}
 
开发者ID:metasfresh,项目名称:metasfresh,代码行数:26,代码来源:PrinterRoutingBL.java

示例7: printZpl

import javax.print.PrintServiceLookup; //导入方法依赖的package包/类
/**
 * Function to print code Zpl to local zebra(usb)
 * 
 * @param zpl
 *            code Zpl to print
 * @param ip
 *            ip adress
 * @param port
 *            port
 * @throws ZebraPrintException
 *             if zpl could not be printed
 */
public static void printZpl(String zpl, String printerName) throws ZebraPrintException {
	try {

		PrintService psZebra = null;
		String sPrinterName = null;
		PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);

		for (int i = 0; i < services.length; i++) {
			PrintServiceAttribute attr = services[i].getAttribute(PrinterName.class);
			sPrinterName = ((PrinterName) attr).getValue();
			if (sPrinterName.toLowerCase().indexOf(printerName) >= 0) {
				psZebra = services[i];
				break;
			}
		}

		if (psZebra == null) {
			throw new ZebraPrintNotFoundException("Zebra printer not found : " + printerName);
		}
		DocPrintJob job = psZebra.createPrintJob();

		byte[] by = zpl.getBytes();
		DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
		Doc doc = new SimpleDoc(by, flavor, null);
		job.print(doc, null);

	} catch (PrintException e) {
		throw new ZebraPrintException("Cannot print label on this printer : " + printerName, e);
	}
}
 
开发者ID:w3blogfr,项目名称:zebra-zpl,代码行数:43,代码来源:ZebraUtils.java

示例8: DruckerController

import javax.print.PrintServiceLookup; //导入方法依赖的package包/类
public DruckerController(DruckerModel model, JFrame parent, 
    MailMergeParams mmp) {
  
  this.mmp = mmp;
  this.model = model; 
  this.parent = parent;
  model.setDrucker(
    PrintParametersDialog.getCurrentPrinterName(
      mmp.getMMC().getTextDocument()));   
  
  PrintService[] printservices = PrintServiceLookup.lookupPrintServices(null,  null); 
  for ( PrintService service : printservices) {
    alleDrucker.add(service.getName());      
  }
  model.setAlleDrucker(alleDrucker);
}
 
开发者ID:WollMux,项目名称:WollMux,代码行数:17,代码来源:DruckerController.java

示例9: out

import javax.print.PrintServiceLookup; //导入方法依赖的package包/类
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;
}
 
开发者ID:cping,项目名称:RipplePower,代码行数:21,代码来源:PrintImageOutput.java

示例10: testListPrinterTrays

import javax.print.PrintServiceLookup; //导入方法依赖的package包/类
@Test
public void testListPrinterTrays ()
{
  final PrintService [] aAllServices = PrintServiceLookup.lookupPrintServices (null, null);
  for (final PrintService aService : aAllServices)
  {
    s_aLogger.info (aService.toString ());
    final Object aAttrs = aService.getSupportedAttributeValues (Media.class,
                                                                DocFlavor.SERVICE_FORMATTED.PAGEABLE,
                                                                null);
    if (ArrayHelper.isArray (aAttrs))
    {
      for (final Media aElement : (Media []) aAttrs)
        if (aElement instanceof MediaTray)
          s_aLogger.info ("  " + aElement);
    }
  }
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:19,代码来源:JavaPrinterTrayFinderFuncTest.java

示例11: findPrinters

import javax.print.PrintServiceLookup; //导入方法依赖的package包/类
/**
 * Find all the printer resources on the server
 * 
 * @return
 */
public static List findPrinters( )
{
	List printers = new ArrayList( );

	PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet( );
	DocFlavor flavor = DocFlavor.INPUT_STREAM.POSTSCRIPT;
	PrintService[] printServices = PrintServiceLookup.lookupPrintServices(
			flavor, pras );
	if ( printServices != null )
	{
		for ( int i = 0; i < printServices.length; i++ )
		{
			PrintService service = printServices[i];
			printers.add( createPrinter( service ) );
		}
	}

	return printers;
}
 
开发者ID:eclipse,项目名称:birt,代码行数:25,代码来源:PrintUtility.java

示例12: main

import javax.print.PrintServiceLookup; //导入方法依赖的package包/类
public static void main(String args[]) throws Exception {
    DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
    PrintService[] pss = PrintServiceLookup.lookupPrintServices(flavor, null);
    PrintService ps = null;
    System.out.println("---- print service");
    for (PrintService _ps : pss) {
        System.out.println(_ps.getName());
        if (_ps.getName().equals(args[0])) {
            ps = _ps;
        }
    }
    for (int i = 0; i < 1; i++) {
        if (ps == null) {
            PDFPrint.print(new File(args[1]));
        } else {
            PDFPrint.print(new File(args[1]),1,ps);
        }
    }
}
 
开发者ID:montsuqi,项目名称:monsiaj,代码行数:20,代码来源:PDFPrint.java

示例13: printComponent

import javax.print.PrintServiceLookup; //导入方法依赖的package包/类
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);
}
 
开发者ID:OpenSourcePhysics,项目名称:osp,代码行数:21,代码来源:PrintUtils.java

示例14: findPrintService

import javax.print.PrintServiceLookup; //导入方法依赖的package包/类
private static PrintService findPrintService(String printerName) {
    PrintService[] printServices = PrintServiceLookup.lookupPrintServices(null, null);
    for (PrintService printService : printServices) {
        if (printService.getName().trim().equals(printerName)) {
            return printService;
        }
    }
    return null;
}
 
开发者ID:CoffeeCodeSwitzerland,项目名称:Lernkartei_2017,代码行数:10,代码来源:Printer.java

示例15: run

import javax.print.PrintServiceLookup; //导入方法依赖的package包/类
public void run()
{
    HashPrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    aset.add(new Copies(2)); // silly request but cuts out fax, xps, etc.
    PrintService[] printServices = PrintServiceLookup.lookupPrintServices(DocFlavor.SERVICE_FORMATTED.PRINTABLE, aset);
    for (PrintService ps : printServices) {
        log.log(Level.INFO, "Found printer: {0}", ps);
        printers.addItem(ps);
        if (ps.getName().equals(Prefs.getDefaultPrinter()))
            printers.setSelectedItem(ps);
    }
}
 
开发者ID:drytoastman,项目名称:scorekeeperfrontend,代码行数:13,代码来源:EntryPanel.java


注:本文中的javax.print.PrintServiceLookup.lookupPrintServices方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。