打印支持应用 v4 API 设计指南

打印支持应用 v4 API 支持虚拟打印机体系结构,以方便在没有旧版第三方驱动程序的情况下实现虚拟打印机。 通过此体系结构,独立软件供应商(ISV)能够将虚拟打印机作为应用程序实现旧版第三方 V3/V4 驱动程序当前支持的功能。 本文介绍如何将应用程序注册为虚拟打印机,以及如何实现实现所需的 PDL 转换和 UI 元素。

打印支持应用(PSA)是引入的体系结构,可帮助 IHV 在不使用旧版第三方驱动程序的情况下向 IPP 打印机添加自定义项。 为了便于过渡到新的虚拟打印机,所有 API 都是打印支持应用* API 命名空间的一部分,并重复使用适用于虚拟打印机体系结构的一些 PSA 协定。

有关详细信息,请参阅以下文章:

主题 描述
打印支持应用设计指南 为正在为其设备实施打印支持应用(PSA)的打印机 OEM 和 IHV 提供指导和示例。
打印支持应用 v3 API 设计指南 为打印机 OEM 和 IHV 提供指南和示例,帮助他们为其设备实现 v3 打印支持应用程序 (PSA)。
打印支持虚拟打印机的 MSIX Manifest 规范 为正在实现打印支持虚拟打印机的打印机 OEM 和 IHV 提供 MSIX 清单指南和示例。
打印支持应用关联 提供有关将打印支持应用(PSA)与打印机相关联的指导和示例。

本文介绍如何扩展 PSA API 以支持软件端点以及 IHV 所需的一些其他 PSA 场景。

术语

Term 定义
PSA 打印支持应用程序。 使用本文档中 API 的 UWP 应用程序。
MXDC Microsoft XPS 文档转换器
MPD 新式打印对话框。 当应用使用 Windows.Graphics.Printing API 打印时,向用户显示此对话框。
CPD 常见打印对话框。 当应用使用 Win32 API 打印时,向用户显示此对话框。
IPP Internet 打印协议。 从客户端设备用于与打印机交互以检索和设置打印首选项,并发送要打印的文档。
打印支持关联的打印机 链接到 PSA 的物理 IPP 打印机。
IPP 打印机 支持 IPP 协议的打印机。
MSDW Microsoft文档编写器
打印机首选项用户界面 用户可以在此对话框中更改打印时将应用的打印机首选项。 示例包括方向、纸张大小、颜色、两侧打印等。
PDL 页面说明语言。 将文档发送到打印机的格式。
关联的 PSA 打印机 每个 PSA 都与物理 IPP 打印机相关联。
PDC 用于定义打印机功能的 PrintDeviceCapabilities XML 文档格式。
SoftwareAppMon 新虚拟打印机队列的端口监视器 DLL
PrintSupportExtension PSA 后台任务负责提供打印机约束扩展功能。
  • 虚拟打印机作为 IppPrintDevice - IppPrintDevice 是作为 PSA API 的一部分引入的 Winrt 类。 虚拟打印机作为 IPP 打印机设备添加,并且 IppPrinterDevice::IsIppPrinter 会为新添加的虚拟打印机返回 true。 因此,PDL 直通可无缝适用于虚拟打印机和 IPP 打印机,并且能够重用现有的许多 PSA API 接口。 IppPrintDevice 类函数(GetPrinterAttributesAsBufferGetPrinterAttributesSetPrinterAttributesFromBuffer,以及 SetPrinterAttributes)已经针对虚拟打印机进行了相应的更改。 GetPrinterAttributesAsBufferGetPrinterAttributes 对于传入的任何 IPP 属性始终返回“不支持”,SetPrinterAttributesFromBufferSetPrinterAttributes 对于虚拟打印机始终返回错误结果,且错误设置为“访问被拒绝”。 这是因为虚拟打印机仅在 appx 清单中指定 PDC,并且不支持任何 IPP 打印机属性。

  • Windows.printSupportSettingsUI 合同在虚拟打印机中的重用 - Windows.printSupportSettingsUI 是作为 PSA 的一部分引入的 UI 合同,用于显示使用 PSA 的用户的 IPP 打印机自定义打印首选项 UI。 本文中的打印支持应用 v4 API 示例重复使用相同的协定,以支持虚拟打印机 UI 的自定义打印首选项,而无需进行任何更改。

  • windows.printSupportJobUI 合同在虚拟打印机中的重用 - Windows.printSupportJobUI 是作为 PSA 的一部分引入的 UI 合同,旨在当 PSA 需要用户输入或向用户显示打印预览时向用户显示 UI。 此协定将重复使用,以便虚拟打印机向用户显示 UI 以供输入或显示预览。 有关详细信息,请参阅 软件终结点 UI 示例,了解 Windows.printSupportJobUI 协定中对 API 所做的更改。

  • windows.printSupportExtension 合同在虚拟打印机中的重用 - Windows.printSupportExtension 是作为 PSA 的一部分引入的后台合同,如果 PSA 想要自定义打印工单验证和其他功能,则可以使用。 如果应用想要对打印票证或 PDC 重新生成进行自定义验证,则虚拟打印机还可以重复使用此协定。

下图描述了虚拟打印机的打印工作流。

显示虚拟打印机的打印工作流的图像。

本部分介绍如何使用 appx 清单条目安装虚拟打印机,以及如何在各种方案中调用虚拟打印机。

Windows.PrintSupportVirtualPrinterWorkflow 合同

要将应用程序注册为虚拟打印机, 需要包含作为 UWP appx 包或 MSIX 安装程序一部分的 XML 清单。

下面的示例是虚拟打印机的 Appx 清单,以及每个字段引用的内容的说明。

<Extensions>
    <printsupport2:Extension Category="windows.printSupportVirtualPrinterWorkflow" EntryPoint="Tasks.PrintSupportWorkflowBackgroundTask">
        <printsupport2:PrintSupportVirtualPrinter DisplayName="ms-resource://PRINTER_NAME1" PrinterUri="contoso-psa:printer1" PreferredInputFormat="application/postscript" OutputFileTypes="ps;pdf" PdcFile="Config\PRINTER_PDC1.xml" PdrFile="Config\PRINTER_PDR1.xml">
            <printsupport2:SupportedFormats>
                <printsupport2:SupportedFormat Type="application/postscript" />
                <printsupport2:SupportedFormat Type="application/pdf" MaxVersion="1.7" />
            </printsupport2:SupportedFormats>
        </printsupport2:PrintSupportVirtualPrinter>
    </printsupport2:Extension>
    <printsupport2:Extension Category="windows.printSupportVirtualPrinterWorkflow" EntryPoint="Tasks.PrintSupportWorkflowBackgroundTask">
        <printsupport2:PrintSupportVirtualPrinter DisplayName="ms-resource://PRINTER_NAME2" PrinterUri ="contoso-psa:printer2" PreferredInputFormat="application/oxps" OutputFileTypes="pwgr;pdf" PdcFile=" Config\PRINTER_PDC2.xml" PdrFile=" Config\PRINTER_PDR2.xml">
            <printsupport2:SupportedFormats>
                <printsupport2:SupportedFormat Type="application/pdf" MaxVersion="1.7" />
            </printsupport2:SupportedFormats>
        </printsupport2:PrintSupportVirtualPrinter>
    </printsupport2:Extension>
    <printsupport:Extension Category="windows.printSupportExtension" EntryPoint="Tasks.PrintSupportExtensionBackGroundTask"/>
    <printsupport:Extension Category="windows.printSupportSettingsUI" EntryPoint="PrintSupportApp.App"/>
    <printsupport:Extension Category="windows.printSupportJobUI" EntryPoint="PrintSupportApp.App"/>
</Extensions>

这是一个用于安装虚拟打印机队列的合同,并且还可作为已安装虚拟打印机的后台端点。 单个 appx 清单可以安装多个打印队列,该队列与同一已安装的应用程序相关联。 当用户打印到新的虚拟打印机队列时,虚拟打印机应用程序将在后台启动,并以 PrintWorkflowVirtualPrinterDataAvailableEventArgs 运行时类作为事件参数引发事件。 运行时类具有用于读取 PDL 数据的 API、应用程序的启动 UI(如果需要)等。

  • PrintSupportVirtualPrinter - 每个条目均指定要随应用程序一起安装的软件终结点打印队列。

  • PreferredInputFormat - 此字段指示虚拟打印机的首选输入 PDL 格式。 Windows 打印系统在为所有打印路径向虚拟打印机提供 PDL 数据之前会生成此格式。 该字段只能是以下值:application/oxps 或 application/postscript。 如果在此字段中指定了其他格式,则安装将失败。 如果未指定字段,则 application/oxps 设置为已安装的虚拟打印机的首选输入 PDL 格式。

  • OutputFileTypes - 在 appx 清单中指定此字段时,Windows 打印系统将创建标记为文件打印机的打印机队列,当应用程序开始打印到虚拟打印机时,向用户显示“另存为”对话框。 此字段的值应包含目标文件扩展名,如 pdf/pwgr/ps 等。这些值存储在驱动程序数据中,并作为允许的扩展添加到“另存为对话框”。 Windows 打印系统为用户所选文件创建 StorageFile 类,并将其作为事件 Args API 的一部分提供给虚拟打印机应用。 如果虚拟打印机不希望文件打印行为(这包括将打印数据存储到云的虚拟打印机或将数据发送到 OneNote 等应用程序的打印机),则不应将此字段添加到清单中。

显示“将打印输出另存为”对话框的图像。

  • 支持的格式 - 虚拟打印机可以使用此字段指定它可以处理的所有 PDL 格式。 这用于像 Microsoft Edge 这样的直通打印应用程序,以识别支持的格式(如 PDF),并将 PDF 流直接传递到虚拟打印机,而无需经过 Windows 打印系统进行任何更改。 此字段将 SupportedFormat 作为子字段。 SupportedFormat 具有字段类型来指定支持的 MIME 类型,字段 MaxVersion 指定虚拟打印机可以接收的 PDL 格式的最大版本。 MaxVersion 值的格式必须为 MajorVersion.MinorVersion。 如果 Windows 打印系统采用任何其他格式,则打印机安装失败。 如果存在任何字符,则 MajorVersion 和 MinorVersion any 仅为数字,version 字段将失效并被忽略。

  • PdcFile - 此字段必须指向应用程序包中的资源文件。 该文件应包含打印设备功能 xml 格式的内容,该格式用于定义打印机功能,并应用于定义任何自定义功能、选项或参数。 如果值不存在,或者文件内容不是有效的 PDC 格式,则这是强制字段,打印机安装将失败。

  • PdrFile - 如果提供此字段,则必须指向应用程序包中的资源文件。 该文件应包含 XML 格式的打印设备资源。 如果应用想要本地化自定义打印首选项,则应提供此字段。 此字段是可选的,打印首选项的资源本地化由打印系统完成(如果此字段不存在)。

  • DisplayName - 指定已安装的虚拟打印机队列的名称。 此字符串的限制与你对 Windows 打印机名称的限制相同。

  • PrinterUri - 指定可供 PSA 应用程序用来标识打印机的唯一 URI。 单个虚拟打印机应用可以指定多个软件终结点,这会导致安装多个打印机。 PrinterUri 字段可用于区分这些打印机。 这作为来自 IppPrintDevice::PrinterUri API 的输出提供。 如果未指定 URI,Windows 会将任意唯一 URI 分配给打印机。

PDF 和 XPS 打印机的简单软件端点示例

此示例展示了一个软件终结点应用的后台任务,该应用已注册两个终结点:“打印至 PDF”和“打印至 XPS”。 此示例在会话中注册 VirtualPrinterDataAvailable 事件,并调用 start。 当引发事件时,事件参数包含 PDL 流、目标文件、UI 启动器和 PDL 转换器。 应用基于打印机将输入 PDL 格式转换为 PDF 或 XPS,并将生成的内容写入目标文件输出流。

public class VirtualPrinterBackgroundTask
{    
    private BackgroundTaskDeferral taskDeferral;
    private IppPrintDevice printDevice;

    public void Run(IBackgroundTaskInstance taskInstance)
    {
        var virtualPrinterDetails = taskInstance.TriggerDetails as PrintWorkflowVirtualPrinterTriggerDetails;
        taskDeferral = taskInstance.GetDeferral();

        PrintWorkflowVirtualPrinterSession session = virtualPrinterDetails.VirtualPrinterSession;
        session.VirtualPrinterDataAvailable += VirtualPrinterDataAvailable;
        // Get print device for the session
        printDevice = session.Printer;

        // Make sure to register all the event handlers before PrintWorkflowVirtualPrinterSession.Start is called.
        session.Start();
    }

    private async void VirtualPrinterDataAvailable(PrintWorkflowVirtualPrinterSession sender, PrintWorkflowVirtualPrinterDataAvailableEventArgs args)
    {
        PrintWorkflowSubmittedStatus jobStatus = PrintWorkflowSubmittedStatus.Failed;
        try
        {
            PrintWorkflowPdlSourceContent sourceContent = args.SourceContent;
            // This Software Print Support App always expect input as OXPS and to have target file to be present.
            if (sourceContent.ContentType != "application/oxps")
            {
                throw new InvalidDataException();
            }

                
            if (this.printDevice.PrinterUri.AbsolutePath == "print-to-pdf")
            {
                // For print-to-pdf endpoint converts OXPS to PDF and write the pdf contents to target file.

                // Get target file output stream.
                StorageFile targetFile = await args.GetTargetFileAsync();
                IRandomAccessStream outputStream = await targetFile.OpenAsync(FileAccessMode.ReadWrite);
                // Get XPS to PDF PDL converter.
                PrintWorkflowPdlConverter converter = args.GetPdlConverter(PrintWorkflowPdlConversionType.XpsToPdf);
                // Convert XPS to PDF and write contents to outputStream.
                await converter.ConvertPdlAsync(args.GetJobPrintTicket(), sourceContent.GetInputStream(), outputStream.GetOutputStreamAt(0));
                // Complete Endpoint print job.
                jobStatus = PrintWorkflowSubmittedStatus.Succeeded;
            }
            else if (this.printDevice.PrinterUri.AbsolutePath == "print-to-xps")
            {
                // For print-to-xps endpoint directly write input XPS file contents to target file.

                // Get target file output stream.
                StorageFile targetFile = await args.GetTargetFileAsync();
                IRandomAccessStream outputStream = await targetFile.OpenAsync(FileAccessMode.ReadWrite);
                // Copy XPS input stream to target file output stream.
                await RandomAccessStream.CopyAndCloseAsync(sourceContent.GetInputStream(), outputStream.GetOutputStreamAt(0));
                // Complete Endpoint print job.
                jobStatus = PrintWorkflowSubmittedStatus.Succeeded;

            }
            else
            {
                // This Print Support App only has print-to-pdf and print-to-xps printers, 
                throw new InvalidDataException();
            }
        }
        finally
        {
            args.CompleteJob(jobStatus);
            taskDeferral.Complete();
        }
    }
}

从软件终结点后台任务启动 UI

打印支持应用 v4 API 为软件终端的后台任务提供了在需要时向用户显示 UI 的功能。 这使用现有 PSA API PrintWorkflowUILauncher 类。 当后台任务调用 LaunchAndCompleteUIAsync 函数时,应用将在 UI 上下文中使用现有的 PSA 协定 Windows.printSupportJobUI启动。 有关详细信息,请参阅 软件终结点 UI 示例

private async void Session_VirtualPrinterDataAvailable(PrintWorkflowVirtualPrinterSession sender, PrintWorkflowVirtualPrinterDataAvailableEventArgs args)
{
    PrintWorkflowSubmittedStatus jobStatus = PrintWorkflowSubmittedStatus.Failed;

    try
    {
        WorkflowPrintTicket printTicket = args.GetJobPrintTicket();

        bool uiRequired = this.IsUIRequired(printTicket);

        if (!uiRequired)
        {
            // Process content directly if UI is not required
            await this.ProcessContent(args);
           jobStatus = PrintWorkflowSubmittedStatus.Succeeded;
        }
        else if (args.UILauncher.IsUILaunchEnabled())
        {
            // LaunchAndCompleteUIAsync will launch the UI and wait for it to complete before returning 
            PrintWorkflowUICompletionStatus status = await args.UILauncher.LaunchAndCompleteUIAsync();

            if (status == PrintWorkflowUICompletionStatus.Completed)
            {
                await this.ProcessContent(args);
              jobStatus = PrintWorkflowSubmittedStatus.Succeeded;
            }
            else if (status == PrintWorkflowUICompletionStatus.UserCanceled)
            {
                // Log user cancellation and cleanup here.
              jobStatus = PrintWorkflowSubmittedStatus. Canceled;
            }
        }
    }
    finally
    {
        args.CompleteJob(jobStatus);
        taskDeferral.Complete();
    }
}

bool IsUIRequired(WorkflowPrintTicket printDevice)
{
    bool isUIRequired = false;
    // Determine UI needs to be shown to the user for this printer
    // Ex: Show UI to get credentials from the user for storing data onto the cloud
    return isUIRequired;
}

async Task ProcessContent(PrintWorkflowVirtualPrinterDataAvailableEventArgs args)
{
    // Process and write pdl contents to target file
    PrintWorkflowPdlSourceContent sourceContent = args.SourceContent;
    StorageFile targetFile = await args.GetTargetFileAsync();
    IRandomAccessStream outputStream = await targetFile.OpenAsync(FileAccessMode.ReadWrite);
    // Copy XPS input stream to target file output stream.
    await RandomAccessStream.CopyAndCloseAsync(sourceContent.GetInputStream(), outputStream.GetOutputStreamAt(0));
}

软件终结点 UI 示例

此示例显示 PSA UI 合同已修改,现可支持从软件终结点后台任务启动 UI。 PrintWorkflowJobUISession 类已被修改,以包含新事件 VirtualPrinterUIDataAvailable。 从软件终结点后台任务启动 UI 时,将调用新事件。 应用程序可以使用事件 Args 提供的 PDL 源上下文向用户显示预览。

namespace PsaSampleAppV4
{
    sealed partial class App : Application
    {
        protected override void OnActivated(IActivatedEventArgs args)
        {
            if (args.Kind == ActivationKind.PrintSupportJobUI)
            {
                var rootFrame = new Frame();

                rootFrame.Navigate(typeof(JobUIPage));
                Window.Current.Content = rootFrame;
        
                var jobUI = rootFrame.Content as JobUIPage;

                // Get the activation arguments
                var workflowJobUIEventArgs = args as PrintWorkflowJobActivatedEventArgs;

                PrintWorkflowJobUISession session = workflowJobUIEventArgs.Session;
               session.PdlDataAvailable += jobUI.OnPdlDataAvailable;
               session.JobNotification += jobUI.OnJobNotification;
               session.VirtualPrinterUIDataAvailable += jobUI.VirtualPrinterUIDataAvailable;
                // Start firing events
                session.Start(); 
            }
        }
    }
}

namespace PsaSampleAppV4
{
    public sealed partial class JobUIPage : Page
    {
        public JobUIPage()
        {
            this.InitializeComponent();
        }

        public void VirtualPrinterUIDataAvailable (PrintWorkflowJobUISession session, PrintWorkflowVirtualPrinterUIEventArgs args)
        {
            using (args.GetDeferral())
            {
                string jobTitle = args.Configuration.JobTitle;
                string sourceApplicationName = args.Configuration.SourceAppDisplayName;            
                string printerName = args.Printer.PrinterName;

                // Get pdl stream and content type
                IInputStream pdlContent = args.SourceContent.GetInputStream();
                string contentType = args.SourceContent.ContentType;
                this.ShowPrintPreview(jobTitle, pdlContent, contentType);
            }
        }

        private void ShowPrintPreview(string jobTitle, IInputStream pdlContent, string contentType)
        {
             // Show preview to the user
        }
    }
}

更新打印机配置的软件终结点

当用户更改设置时,软件终结点可能需要更改打印机配置。 为此,RefreshPrintDeviceCapabilities 函数已添加到 IppPrintDevice WinRT 类中。 调用此函数时,它会调用 PrintSupportExtensionSession.PrintDeviceCapabilitiesChanged 事件,应用可在其中更新当前打印设备功能。

private void UpdatePrintDeviceCapabilites(string printerName)
{
    IppPrintDevice printer = IppPrintDevice.FromPrinterName(printerName);
    // Call RefreshPrintDeviceCapabilities results in Print Device Capabilites Changed event to be raised
    printer.RefreshPrintDeviceCapabilities();
}

获取和更改默认用户打印票证

IHV 可能需要在从“开始”菜单启动 PSA 应用时显示和修改默认打印首选项。 因此,会将 UserDefaultPrintTicket 属性添加到 IppPrintDevice WinRT 类。 任何应用程序都可以使用此属性获取和设置用户默认打印票证。

// Returns false if the application is not allowed to modify the print ticket
private bool TryModifyDefaultPrintTicket(string printerName)
{
    IppPrintDevice printer = IppPrintDevice.FromPrinterName(printerName);
    WorkflowPrintTicket printTicket =  printer.UserDefaultPrintTicket;

    if (printer.CanModifyUserDefaultPrintTicket)
    {
        printer.UserDefaultPrintTicket = this.ShowPrintTicketOptions(printTicket);
        return true;
    }
    return false;
}

private WorkflowPrintTicket ShowPrintTicketOptions(WorkflowPrintTicket printTicket)
{
    // Show Print Tickets options to the user for modification

    // return Modified print ticket
    return printTicket;
}

使得使用作业特性更轻松

在 IHV 可能需要在向打印机发送创建作业请求之前删除某些属性时,很难创建在打印机上创建作业所需的完整作业属性。 ConvertPrintTicketToJobAttributes 会被添加到 Winrt 类 PrintWorkflowPrintJob,以获取打印机票证的 IPP 特性。 下面的示例展示了 PSA 如何从打印票证中获取 IPP 属性并移除媒体大小属性,之后这些属性将作为发送给打印机的 PDL 内容的一部分。

 private async void OnPdlModificationRequested(PrintWorkflowJobBackgroundSession sender, PrintWorkflowPdlModificationRequestedEventArgs args)
 {
     //....
     PrintWorkflowPrinterJob printjob = args.PrinterJob;
     string pdlFormat = this.GetPdlFormat(printjob.Printer);

     IDictionary<string, IppAttributeValue> attributes = printjob.ConvertPrintTicketToJobAttributes(printjob.GetJobPrintTicket(), pdlFormat);
     var operationalAttributes = new Dictionary<string, IppAttributeValue>();

     PrintWorkflowPdlTargetStream targetStream = args.CreateJobOnPrinterWithAttributes(this.RemoveMediaSize(attributes), pdlFormat,
         operationalAttributes, PrintWorkflowAttributesMergePolicy.DoNotMergeWithPrintTicket,
         PrintWorkflowAttributesMergePolicy.MergePreferPrintTicketOnConflict);

     //.....
 }

 // Remove Media size from attributes as media size will sent to the printer as part of the PDL header
 private IDictionary<string, IppAttributeValue> RemoveMediaSize(IDictionary<string, IppAttributeValue> attributes)
{
    IppAttributeValue mediaCol = null;

    if (attributes.TryGetValue("media-col", out mediaCol))
    {
        var newMediaCol = new Dictionary<string, IppAttributeValue>(mediaCol.GetCollectionArray()[0]);
        newMediaCol.Remove("media-size");
        attributes["media-col"] = IppAttributeValue.CreateCollection(newMediaCol);
    }

    return attributes;
}

 private string GetPdlFormat(IppPrintDevice printer)
 {
     string pdlFormat = "application/pdf";
     // Get preferred PDL format from printer
     return pdlFormat;
}

根据页面输出质量配置 MXDC 的图像质量

当前的旧版第三方 V4 打印驱动程序可以根据页面质量指定 MXDC 生成的图像质量。 有关详细信息,请参阅 V4 驱动程序清单

为了弃用旧式第三方 V3/V4 驱动程序,需要使用 PSA API 为此功能提供奇偶校验。 因此,PSA v4 API 提供了用于获取和设置图像质量配置的 WinRT 类。

private void PrintDeviceCapabilitiesChanged(PrintSupportExtensionSession sender, PrintSupportPrintDeviceCapabilitiesChangedEventArgs args)
{
    //....
    this.SetImageQualityForPrinter(this.printDevice, args.MxdcImageQualityConfiguration);
    //....
}

private void SetImageQualityForPrinter(IppPrintDevice printDevice, PrintSupportMxdcImageQualityConfiguration mxdcImageQualityConfiguration)
{
    //....
    // Set image quality for large scale printer
    mxdcImageQualityConfiguration.TextOutputQuality = XpsImageQuality.JpegHighCompression;
    mxdcImageQualityConfiguration.DraftOutputQuality = XpsImageQuality.JpegMediumCompression;
    mxdcImageQualityConfiguration.NormalOutputQuality = XpsImageQuality.JpegLowCompression;
    mxdcImageQualityConfiguration.HighOutputQuality = XpsImageQuality.Png;
    mxdcImageQualityConfiguration.PhotographicOutputQuality = XpsImageQuality.Png;
    mxdcImageQualityConfiguration.AutomaticOutputQuality = XpsImageQuality.JpegMediumCompression;
    mxdcImageQualityConfiguration.FaxOutputQuality = XpsImageQuality.JpegMediumCompression;
}

在 App WinAppSdk 中实现 PrintSupportSettingUI 合同

Print Support App v4 API 在 PrintSupportSettingsActivatedEventArgs WinRT 类中引入了一个属性,名为 所有者窗口ID。 Windows 应用 SDK 应用程序负责将其窗口创建为给定 OwnerWindowId 窗口的模式。

protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs a)
{
    AppActivationArguments args = Microsoft.Windows.AppLifecycle.AppInstance.GetCurrent().GetActivatedEventArgs();

    if (args.kind == ExtendedActivationKind.PrintSupportSettingsUI)
    {
        var settingsArgs = args.Data as PrintSupportSettingsActivatedEventArgs;
        Microsoft.UI.WindowId ownerWindowId;
        ownerWindowId.Value = settingsArgs.OwnerWindowId.Value;
        var ownerHwnd = Microsoft.UI.Win32Interop.GetWindowFromWindowId(ownerWindowId);
        this.CreateAppWindowAsModel(ownerHwnd);
    }
}

言论

本文中的示例基于 PSA v1、PSA v2 API 和 PSA v3 API 的示例构建,假设开发人员熟悉 PSA API 工作流。

本文包含打印支持应用设计指南中所述的现有公共打印支持应用程序 API 的扩展,以及 Windows.Graphics.Printing.PrintSupport 命名空间。 PSA API 使打印机制造商能够开发 UWP 应用,这些应用可以在使用收件箱Microsoft IPP 类驱动程序时增强 Windows 用户打印体验,而无需开发自定义驱动程序。

打印组件正通过 PSA 代理进程与 PSA 应用通信。

ConvertPrintTicketToJobAttributes

Windows 上第三方打印机驱动程序服务计划的结束

GetPrinterAttributesAsBuffer

GetPrinterAttributes

IppPrintDevice

IppPrinterDevice::IsIppPrinter

IppPrintDevice::PrinterUri

LaunchAndCompleteUIAsync

OwnerWindowId

PrintSupportExtensionSession.PrintDeviceCapabilitiesChanged

PrintSupportSettingsActivatedEventArgs

PrintWorkflowJobUISession

PrintWorkflowPrintJob

PrintWorkflowUILauncher

RefreshPrintDeviceCapabilities

设置打印机属性

SetPrinterAttributesFromBuffer

软件终结点 UI 示例

储存文件

UserDefaultPrintTicket

VirtualPrinterDataAvailable

VirtualPrinterUIDataAvailable

Windows.Graphics.Printing.PrintSupport