मैं एक संवाद में प्रिंटर स्थान दिखाने का प्रयास कर रहा हूं। लेकिन मेरे आश्चर्य की बात है कि, किसी भी प्रिंट सेवा में स्थान विशेषता नहीं होती है - हालांकि मैंने सत्यापित किया है कि मेरे कुछ प्रिंटर विंडोज प्रिंटर नियंत्रण कक्ष में एक स्थान प्रदर्शित करते हैं।प्रिंटर का स्थान कैसे प्राप्त करें
मैंने इस कोड का उपयोग स्थानों को मुद्रित करने के लिए किया था (यह हमेशा स्थान के लिए "शून्य" प्रिंट करता है)। मेरा जावा संस्करण 1.7.0_21:
public class PrintLocation {
public static void main(String[] argv) {
PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);
for (PrintService service : services) {
Object location = service.getAttribute(PrinterLocation.class);
System.out.println(service.getName() + " - " + location);
}
}
}
क्या यह जेआरई द्वारा समर्थित/कार्यान्वित नहीं है या क्या मैं यहां कुछ गलत कर रहा हूं? मैं प्रिंटर का स्थान कैसे प्राप्त कर सकता हूं?
संपादित करें: मेरे मशीन पर आउटपुट है:
\\srv51\SIR-2725-01_KX_color - null
\\srv51\SIR-2725-01_KX_sw - null
Microsoft XPS Document Writer - null
Microsoft Office Document Image Writer - null
FreePDF XP - null
EDIT2: के रूप में सुझाव दिया है, मैं सभी विशेषताओं बाहर मुद्रित:
PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);
for (PrintService service : services) {
PrintServiceAttributeSet attrs = service.getAttributes();
System.out.println("Service: " + service.getName());
int i = 1;
for (Object attr : attrs.toArray()) {
System.out.println("Attr #" + i + ": " + attr.getClass().getSimpleName()
+ ", " + attr);
++i;
}
}
और मुझे मिल गया:
Service: \\srv51\SIR-2725-01_KX_color
Attr #1: ColorSupported, supported
Attr #2: PrinterName, \\srv51\SIR-2725-01_KX_color
Attr #3: QueuedJobCount, 0
Attr #4: PrinterIsAcceptingJobs, accepting-jobs
Service: \\srv51\SIR-2725-01_KX_sw
Attr #1: ColorSupported, supported
Attr #2: PrinterName, \\srv51\SIR-2725-01_KX_sw
Attr #3: QueuedJobCount, 0
Attr #4: PrinterIsAcceptingJobs, accepting-jobs
Service: Microsoft XPS Document Writer
Attr #1: ColorSupported, supported
Attr #2: PrinterName, Microsoft XPS Document Writer
Attr #3: QueuedJobCount, 0
Attr #4: PrinterIsAcceptingJobs, accepting-jobs
Service: Microsoft Office Document Image Writer
Attr #1: ColorSupported, not-supported
Attr #2: PrinterName, Microsoft Office Document Image Writer
Attr #3: QueuedJobCount, 0
Attr #4: PrinterIsAcceptingJobs, accepting-jobs
Service: FreePDF XP
Attr #1: ColorSupported, supported
Attr #2: PrinterName, FreePDF XP
Attr #3: QueuedJobCount, 0
Attr #4: PrinterIsAcceptingJobs, accepting-jobs
तो , मेरी मशीन पर किसी भी प्रिंटर के लिए कोई प्रिंटर स्थान नहीं है।
करें और देखें कि 'PrinterLocation' है। – selig
@selig अच्छा विचार, यह पता चला है कि यह वहां भी नहीं है। – Durandal