本文整理汇总了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;
}
示例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");
}
示例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");
}
}
示例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();
}
}
}
示例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();
}
}
}
示例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;
}
示例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);
}
}
示例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);
}
示例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;
}
示例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);
}
}
}
示例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;
}
示例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);
}
}
}
示例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);
}
示例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;
}
示例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);
}
}