java 打印位置设置_java – 如何获取打印机的位置

我正在尝试在对话框中显示打印机位置。但令我吃惊的是,打印服务似乎没有位置属性 – 尽管我已经确认我的某些打印机在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。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值