當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。