如何打印而不显示打印对话?

时间:2014-01-09 11:59:34

标签: c# .net wpf printing

我有这个演示应用程序,我需要打印FlowDocument而不从操作系统弹出打印对话框。你知道怎么做吗?或者你知道其他可能的解决方案吗?

private void Button_Click(object sender, RoutedEventArgs e)
{
    PrintDialog pd = new PrintDialog();
    pd.ShowDialog();
    if (pd.ShowDialog() != true) return;

    flowDocument.PageHeight = pd.PrintableAreaHeight;
    flowDocument.PageWidth = pd.PrintableAreaWidth;

    IDocumentPaginatorSource idocument = flowDocument as IDocumentPaginatorSource;

    pd.PrintDocument(idocument.DocumentPaginator, "Printing Flow Document...");
}

1 个答案:

答案 0 :(得分:4)

删除这一行:

pd.ShowDialog();
if (pd.ShowDialog() != true) return;