15

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

Thanks for help…

Vadim Ovchinnikov
  • 13,327
  • 5
  • 62
  • 90
Raj
  • 3,890
  • 7
  • 52
  • 80

3 Answers3

19

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

Nir
  • 29,306
  • 10
  • 67
  • 103
17

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);
viggity
  • 15,039
  • 7
  • 88
  • 96
el_shayan
  • 2,735
  • 4
  • 28
  • 42
  • 4
    Unfortunately if you try to print to file there is a dialog, anyone know the solution for print to file? – Beno Aug 28 '12 at 04:12
3

Try

PrintDialog dialog = new PrintDialog();
dialog.PrintVisual(_PrintCanvas, "My Canvas");
Serve Laurijssen
  • 9,266
  • 5
  • 45
  • 98