首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何获取打印机的位置

如何获取打印机的位置
EN

Stack Overflow用户
提问于 2013-06-14 00:50:46
回答 1查看 912关注 0票数 16

我正在尝试在对话框中显示打印机位置。但令我惊讶的是,似乎没有任何打印服务具有位置属性-尽管我验证了我的一些打印机确实在windows打印机控制面板中显示了位置。

我使用此代码来打印位置(它总是打印位置的"null“)。我的Java版本是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);
    }
}

}

这是JRE不支持/实现的,还是我做错了什么?如何获取打印机的位置?

编辑:我机器上的输出是:

\\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。

EN

回答 1

Stack Overflow用户

发布于 2013-06-14 06:41:17

来自http://download.java.net/jdk8/docs/api/javax/print/attribute/package-summary.html

一旦打印机开始处理打印作业,有关该作业的其他信息就会变为可用,这些信息可能包括:作业状态(如已完成或已排队)以及到目前为止打印的页数。这些信息也是属性。属性还可以描述打印机本身,例如:打印机名称、打印机位置和排队的作业数。

不确定这是否意味着它在启动进程后变得可用

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17092729

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档