如何在WPF中直接打印而无需使用打印对话框?

15
我想知道如何在WPF中打印Flow Document而不显示打印对话框。
谢谢帮助...
3个回答

19

您可以在不显示对话框的情况下(即不调用ShowModal)使用PrintDialog类。


17

以下是一种更改默认打印机或更改其他设置的方法:

using System.Printing;  //add reference to System.Printing Assembly
                        //if you want to modify PrintTicket, also add
                        //reference to ReachFramework.dll (part of .net install)
...

var dlg = new PrintDialog();

dlg.PrintQueue = printer; // this will be your printer. any of these: new PrintServer().GetPrintQueues()
dlg.PrintTicket.CopyCount = 3; // number of copies
dlg.PrintTicket.PageOrientation = PageOrientation.Landscape;

dlg.PrintVisual(canvas);

4
很不幸,如果您尝试打印到文件,将会出现对话框,有人知道打印到文件的解决方案吗? - Beno

3

尝试

PrintDialog dialog = new PrintDialog();
dialog.PrintVisual(_PrintCanvas, "My Canvas");

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接