WPF中的文档打印

C#代码:
    string printFileName = @"C:/TestForPrint.xps";
    public void InvokePrint(object sender, RoutedEventArgs e)
    {
        // 打印对话框,设置属性
        PrintDialog pDialog = new PrintDialog();
        pDialog.PageRangeSelection = PageRangeSelection.AllPages;
        pDialog.UserPageRangeEnabled = true;
        // 这里你还可以设置对话框的MaxPage, MinPage, PageRange, PrintableAreaHeight, PrintableAreaWidth, PrintQueue, PrintTicket属性值等。
        // 显示对话框,如果用户点击“打印”按钮,则返回true。
        Nullable<Boolean> print = pDialog.ShowDialog();
        if (print == true)
        {
            XpsDocument xpsDocument = new XpsDocument(printFileName, FileAccess.ReadWrite);
            FixedDocumentSequence fixedDocSeq = xpsDocument.GetFixedDocumentSequence();
            pDialog.PrintDocument(fixedDocSeq.DocumentPaginator, "Test print");
        }
    } 

原文地址:https://www.cnblogs.com/luluping/p/2605778.html