Print Multiple Pages From a UWA
<p>I have about 8 records that I want to print in one batch, each on a separate page. However, the UWP sample for this uses over 600 lines of code to accomplish it. It seems to me that it has to be much, much easier than that. I thought all we'd have to do is add each page to the <code>PrintDocument</code> and send the print job. Apparently not. I'm using this:</p>

<pre><code>async void Print()
{
    var printDocument = new PrintDocument();
    var printDocumentSource = printDocument.DocumentSource;
    var printMan = PrintManager.GetForCurrentView();
    printMan.PrintTaskRequested += PrintTaskRequested;

    var pages = new List&lt;Page&gt;();

    foreach (var item in items)
    {
        (//Set up variables)

        var printPage = new PageToPrint() { //Set properties };
        printPage.Set_Up();  //Set up fields

        pages.Add(printPage);
    }

    printDocument.SetPreviewPage(1, page);
    printDocument.SetPreviewPageCount(pages.Count, PreviewPageCountType.Final);

    foreach (var page in pages)
    {
        printDocument.AddPage(page);
    }

    printDocument.AddPagesComplete();
    await PrintManager.ShowPrintUIAsync();
}

void PrintTaskRequested(PrintManager sender, PrintTaskRequestedEventArgs e)
{
    PrintTask printTask = null;
    printTask = e.Request.CreatePrintTask("Kimble Print Job", sourceRequested =&gt;
    {
        printTask.Completed += PrintTask_Completed;
        sourceRequested.SetSource(printDocumentSource);
    });
}

private async void PrintTask_Completed(PrintTask sender, PrintTaskCompletedEventArgs args)
{
    await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =&gt;
    {
        PrintManager printMan = PrintManager.GetForCurrentView();
        printMan.PrintTaskRequested -= PrintTaskRequested;
    });
}
</code></pre>

<p>However, it won't generate the print preview. It just sits there spinning and spinning, and if I hit "print" it doesn't succeed (PDF can't open, job never gets to a physical printer.)</p>

<p>I was hoping printing would be at least <em>reasonably</em> easy with the <code>PrintDocument</code>, and I still think it looks like it should be. Am I just missing it here, or does it really take 600+ lines of code to dispatch a simple print job?</p>