Deepan Balachandar
Deepan Balachandar

Reputation: 141

Select Printer after Previewing the document

I'm using the PrintPreviewDialog. Works great, but I really need to allow the user to select a printer instead of just having the print go directly to the default printer.

Upvotes: 1

Views: 98

Answers (1)

Noam M
Noam M

Reputation: 3164

Try to use the PrintDialog class, for example in the next manner:

<Button Width="200" Click="InvokePrint">Invoke PrintDialog</Button>

private void InvokePrint(object sender, RoutedEventArgs e)
{
    // Create the print dialog object and set options
    PrintDialog pDialog = new PrintDialog();
    pDialog.PageRangeSelection = PageRangeSelection.AllPages;
    pDialog.UserPageRangeEnabled = true;

    // Display the dialog. This returns true if the user presses the Print button.
    Nullable<Boolean> print = pDialog.ShowDialog();
    if (print == true)
    {
        XpsDocument xpsDocument = new XpsDocument("C:\\FixedDocumentSequence.xps", FileAccess.ReadWrite);
        FixedDocumentSequence fixedDocSeq = xpsDocument.GetFixedDocumentSequence();
        pDialog.PrintDocument(fixedDocSeq.DocumentPaginator, "Test print job");
    }
}

Upvotes: 4

Related Questions