在遵循Microsoft 白皮书中关于在应用程序中实现打印功能的一些指导方针之后,我有一些 WinJS 代码使我能够检索所有连接到 Windows 8 机器的打印设备的枚举。我的问题是,如果我有这些信息,是否可以在不启动用于选择打印机的 UI 的情况下调用与特定打印机的打印合同。
这是枚举连接打印机的代码:
logDevices: function () {
// This is the GUID for printers
var printerInterfaceClass="{0ecef634-6ef0-472a-8085-5ad023ecbccd}";
var selector="System.Devices.InterfaceClassGuid:=\"" + printerInterfaceClass + "\"";
// By default, findAllAsync does not return the containerId
// for the device it queries.
// We have to add it as an additonal property to retrieve.
var containerIdField = "System.Devices.ContainerId";
var propertiesToRetrieve = [containerIdField];
// Asynchronously find all printer devices.
Windows.Devices.Enumeration.DeviceInformation.findAllAsync(selector, propertiesToRetrieve)
.done(function (devInfoCollection) {
console.log("\n[DEV DASH] : -------------------------------------------------------------------------------------------");
devInfoCollection.forEach(function (deviceInfo) {
console.log("[DEV DASH] : Printer : " + deviceInfo['name']);
console.log("[DEV DASH] : ID : " + deviceInfo['id']);
console.log("[DEV DASH] : Enabled : " + deviceInfo['isEnabled']);
console.log("[DEV DASH] : * * * * * * * * * * * * * * * * * * ");
});
console.log("[DEV DASH] : -------------------------------------------------------------------------------------------");
}, function (e) {
console.log("[DEV DASH] : Error in obtaining device information: " + e.message);
});
}
我正在使用以下代码来调出允许用户选择打印设备的 UI,但是有没有办法使用 WinJS 以编程方式实现打印机的选择?
Windows.Graphics.Printing.PrintManager.showPrintUIAsync();
谢谢!