How to print directly, without Print Dialog in WPF?

前端 未结 3 1259
终归单人心
终归单人心 2020-12-28 18:55

I just want to know how I can print a flow document without showing Print Dialog in WPF.

Thanks for help…

相关标签:
3条回答
  • 2020-12-28 19:35

    You can use the PrintDialog class without showing the dialog (without calling ShowModal)

    0 讨论(0)
  • 2020-12-28 19:35

    Try

    PrintDialog dialog = new PrintDialog();
    dialog.PrintVisual(_PrintCanvas, "My Canvas");
    
    0 讨论(0)
  • 2020-12-28 19:39

    This is one of the ways you can change default printer or change other settings:

    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);
    
    0 讨论(0)
提交回复
热议问题