如何从Windows 8应用程序实现对特定打印机的打印

时间:2013-07-19 17:57:31

标签: windows-8 winjs

按照a Microsoft white paper about implementing printing functionality in apps中的一些指导原则,我有一些WinJS代码,可以让我检索所有连接的打印设备的枚举到Windows 8机器。我的问题是,如果我有这些信息,是否可以调用与特定打印机的打印合同,而无需用户界面选择打印机。

以下是枚举连接打印机的代码:

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();

谢谢!

0 个答案:

没有答案