次の方法で共有


印刷サポート アプリ v4 API 設計ガイド

Print Support App v4 API では、従来のサード パーティ製ドライバーを使用せずに仮想プリンターを実装しやすくするために、仮想プリンター アーキテクチャがサポートされています。 このアーキテクチャにより、独立系ソフトウェア ベンダー (ISV) は、従来のサード パーティ製 V3/V4 ドライバーで現在サポートされている機能を実装するアプリケーションとして仮想プリンターを実装できます。 この記事では、アプリケーション自体を仮想プリンターとして登録する方法と、実装に必要な PDL 変換と UI 要素を実装する方法について説明します。

印刷サポート アプリ (PSA) は、IHV が従来のサード パーティ製ドライバーを使用せずに IPP プリンターにカスタマイズを追加するために導入されたアーキテクチャです。 新しい仮想プリンターへの移行を容易にするために、すべての API は印刷サポート アプリ* API 名前空間の一部であり、Virtual Printer アーキテクチャに適用できる一部の PSA コントラクトを再利用します。

詳細については、次の記事を参照してください。

トピック 説明
印刷サポート アプリの設計ガイド デバイスの印刷サポート アプリ (PSA) を実装しているプリンター OEM および IHV のガイダンスと例を示します。
印刷サポート アプリ v3 API 設計ガイド デバイスの v3 印刷サポート アプリ (PSA) を実装しているプリンター OEM および IHV のガイダンスと例を示します。
印刷サポート仮想プリンター向け MSIX マニフェスト仕様 印刷サポート仮想プリンターを実装しているプリンター OEM および IHV の MSIX マニフェスト ガイダンスと例を提供します。
印刷サポート アプリの関連付け 印刷サポート アプリ (PSA) をプリンターに関連付けるガイダンスと例を示します。

この記事では、ソフトウェア エンドポイントと、IHV に必要なその他のいくつかの PSA シナリオをサポートするために、PSA API がどのように拡張されるかについて説明します。

用語

用語 定義
PS4 印刷サポート アプリケーション。 このドキュメントの API を使用する UWP アプリ。
MXDC Microsoft XPS ドキュメント コンバーター
MPD モダンプリントダイアログ。 このダイアログは、アプリが Windows.Graphics.Printing API を使用して印刷しているときにユーザーに表示されます。
CPD 一般的な印刷ダイアログ。 このダイアログは、アプリが Win32 API を使用して印刷しているときにユーザーに表示されます。
IPP インターネット印刷プロトコル。 クライアント デバイスからプリンターを操作して印刷設定を取得および設定し、印刷するドキュメントを送信するために使用します。
印刷サポートが関連付けられているプリンター PSA にリンクされている物理 IPP プリンター。
IPP プリンター IPP プロトコルをサポートするプリンター。
MSDW Microsoft ドキュメント ライター
プリンターの基本設定 UI ユーザーが印刷時に適用されるプリンターに関連する基本設定を変更できるダイアログ。 たとえば、向き、用紙サイズ、色、両面印刷などです。
PDL ページの説明言語。 文書がプリンターに送信される形式。
関連付けされた PSA プリンター すべてのPSAは物理IPPプリンタに関連付けられています。
PDC プリンター機能を定義するための PrintDeviceCapabilities XML ドキュメント形式。
SoftwareAppMon 新しい仮想プリンターキュー用ポートモニターDLL
プリントサポート拡張 PSA バックグラウンド タスクは、プリンター制約拡張機能を提供する役割を担います。
  • 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 コントラクトを Virtual Printer - Windows.printSupportJobUI に再利用することは、ユーザー入力が必要な場合や印刷プレビューをユーザーに表示する場合に、ユーザーの UI を表示するために、PSA の一部として導入された UI コントラクトです。 このコントラクトは、入力の UI をユーザーに表示したり、プレビューを表示したりするために、Virtual Printer に再利用されます。 詳細については、Windows.printSupportJobUI コントラクトで API に加えられた変更の ソフトウェア エンドポイント UI サンプルを参照してください。

  • 仮想プリンターに対する 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>

これは、仮想プリンター キューのインストールに使用されるコントラクトであり、インストールされている仮想プリンターのバックグラウンド エンドポイントとしても機能します。 1 つの appx マニフェストで、同じインストール済みアプリケーションに関連付けられている複数の印刷キューをインストールできます。 ユーザーが新しい仮想プリンター キューに印刷すると、仮想プリンター アプリケーションがバックグラウンドで起動され、PrintWorkflowVirtualPrinterDataAvailableEventArgs ランタイム クラスをイベント引数として使用してイベントが発生します。 ランタイム クラスには、PDL データの読み取り、必要に応じてアプリケーションの UI の起動などの API があります。

  • PrintSupportVirtualPrinter - 各エントリは、アプリケーションと共にインストールする 1 つのソフトウェア エンドポイント印刷キューを指定します。

  • PreferredInputFormat - このフィールドは、仮想プリンターの優先入力 PDL 形式を示します。 Windows 印刷システムでは、すべての印刷パスの PDL データを仮想プリンターに渡す前に、この形式が生成されます。 フィールドには、application/oxps または application/postscript の値のみを指定できます。 このフィールドに他の形式が指定されている場合、インストールは失敗します。 フィールドが指定されていない場合、アプリケーション/oxps は、インストールされている仮想プリンターの優先入力 PDL 形式として設定されます。

  • OutputFileTypes - このフィールドが appx マニフェストで指定されている場合、Windows 印刷システムはファイル プリンターとしてマークされたプリンター キューを作成し、アプリケーションが仮想プリンターへの印刷を開始すると、[名前を付けて保存] ダイアログがユーザーに表示されます。 このフィールドの値には、pdf/pwgr/ps などのターゲット ファイル拡張子が含まれている必要があります。これらの値はドライバー データに格納され、許可された拡張機能として [ダイアログとして保存] に追加されます。 Windows 印刷システムは、ユーザーが選択したファイルの StorageFile クラスを作成し、イベント引数 API の一部として仮想プリンター アプリに渡されます。 仮想プリンターがファイルの印刷動作を望まない場合 (これには、クラウドに印刷データを格納する仮想プリンターや、OneNote などのアプリケーションにデータを送信するプリンターが含まれます)、このフィールドをマニフェストに追加しないでください。

印刷出力を保存するダイアログボックスを示す画像です。

  • サポートされている形式 - 仮想プリンターは、このフィールドを使用して、処理できるすべての PDL 形式を指定できます。 これは、Microsoft Edge などのパススルー印刷アプリケーションで、PDF などのサポートされている形式を識別し、Windows 印刷システムの間で変更を加えずに PDF ストリームを仮想プリンターに直接渡すために使用されます。 このフィールドには、子フィールドとして SupportedFormat があります。 SupportedFormat には、サポートされている MIME の種類を指定するフィールド Type があり、フィールド MaxVersion は、仮想プリンターが受け取ることができる PDL 形式の最大バージョンを指定します。 MaxVersion 値の形式は MajorVersion.MinorVersion である必要があります。 Windows 印刷システムが他の形式の場合、プリンターのインストールが失敗します。 MajorVersion と MinorVersion は数字のみである必要があります。文字があると、そのバージョン フィールドは無効とされ、無視されます。

  • PdcFile - このフィールドは、アプリケーション パッケージ内のリソース ファイルを指す必要があります。 ファイルには、プリンター機能を定義するために使用される印刷デバイス機能 XML 形式の内容が含まれている必要があり、カスタム機能、オプション、またはパラメーターを定義するために使用する必要があります。 これは必須フィールドであり、値が存在しない場合、またはファイルの内容が有効な PDC 形式でない場合、プリンターのインストールは失敗します。

  • PdrFile - 指定された場合、このフィールドはアプリケーション パッケージ内のリソース ファイルを指す必要があります。 ファイルには、XML 形式の印刷デバイス リソースが含まれている必要があります。 アプリでカスタム印刷設定をローカライズする場合は、このフィールドを指定する必要があります。 このフィールドは省略可能であり、このフィールドが存在しない場合は、印刷設定のリソースのローカライズが印刷システムによって行われます。

  • DisplayName - インストールされている仮想プリンター キューの名前を指定します。 この文字列の制限は、Windows プリンター名の制限と同じです。

  • PrinterUri - PS アプリケーションがプリンターを識別するために使用できる一意の URI を指定します。 1 つの仮想プリンター アプリで複数のソフトウェア エンドポイントを指定でき、その結果、複数のプリンターがインストールされます。 PrinterUri フィールドは、これらのプリンターを区別するために使用できます。 これは、IppPrintDevice::P rinterUri API からの出力として提供されます。 URI が指定されていない場合、Windows はプリンターに任意の一意の URI を割り当てます。

PDF および XPS プリンター用のシンプルなソフトウェア エンドポイント サンプル

このサンプルでは、2 つのエンドポイントを登録したソフトウェア エンドポイント アプリのバックグラウンド タスクを示します。PDF に印刷し、XPS に印刷します。 このサンプルは、セッション VirtualPrinterDataAvailable イベントに登録し、呼び出しを開始します。 イベントが発生すると、Event Args には 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 関数を呼び出すと、既存の PSA コントラクト Windows.printSupportJobUIを使用して、UI コンテキスト内でアプリが起動されます。 詳細については、ソフトウェア エンドポイント 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 のサンプル

このサンプルでは、ソフトウェア エンドポイントバックグラウンドタスクからの UI 起動をサポートするように変更されたPSA UI コントラクトを示します。 PrintWorkflowJobUISession クラスに、新しいイベントとして VirtualPrinterUIDataAvailableが追加されます。 ソフトウェア エンドポイントのバックグラウンド タスクから UI を起動すると、新しいイベントが呼び出されます。 アプリケーションは、イベント引数によって提供される 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();
}

既定のユーザー印刷チケットを取得および変更する

スタート メニューから PSA アプリを起動するときに、IHV で既定の印刷設定を表示および変更したい場合があります。 このため、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 が特定の属性を削除する場合、プリンターでジョブを作成するために必要な完全なジョブ属性を作成することは困難な場合があります。 プリンター チケットの IPP 属性を取得するために、ConvertPrintTicketToJobAttributes が Winrt クラス PrintWorkflowPrintJob に追加されます。 次の例は、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 クラスのプロパティ OwnerWindowIdが導入されています。 Windows App 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);
    }
}

Remarks

この記事のサンプルは、開発者がPSA API ワークフローに慣れているという前提で、PSA v1、PSA v2 API、およびPSA v3 API のサンプルに基づいて構築されています。

この記事には、「印刷サポート アプリの設計ガイド」および「Windows.Graphics.Printing.PrintSupport 名前空間 説明されている既存のパブリック印刷サポート アプリケーション API の拡張機能が含まれています。 PSA API を使用すると、プリンターの製造元は、カスタム ドライバーを開発することなく、受信トレイ Microsoft IPP クラス ドライバーを使用しながら Windows ユーザーの印刷エクスペリエンスを強化できる UWP アプリを開発できます。

印刷コンポーネントは、PSA ブローカー プロセスを通じて、PSA アプリと通信しています。

ConvertPrintTicketToJobAttributes

Windows でのサード パーティ製プリンター ドライバーのサービス終了プラン

GetPrinterAttributesAsBuffer

GetPrinterAttributes

IppPrintDevice

IppPrinterDevice::IsIppPrinter

IppPrintDevice::PrinterUri

LaunchAndCompleteUIAsync

OwnerWindowId

PrintSupportExtensionSession.PrintDeviceCapabilitiesChanged

PrintSupportSettingsActivatedEventArgs

PrintWorkflowJobUISession

PrintWorkflowPrintJob

PrintWorkflowUILauncher

RefreshPrintDeviceCapabilities

に SetPrinterAttributes を設定する

バッファーからプリンター属性を設定

ソフトウェア エンドポイント UI のサンプル

StorageFile

UserDefaultPrintTicket

VirtualPrinterDataAvailable

VirtualPrinterUIDataAvailable

Windows.Graphics.Printing.PrintSupport