I'm tring to write a C# console application (.NET Framework 4.5) which should be able to create "print job" (a file that can be sent directly to printer) without asking information to user.
In particular I'm tring to use PrintVisual function with PrintQueue and PrintTicket as follow:
[STAThread]
static void Main(string[] args)
{
PrintQueue printQueue = GetPrintQueues("MyPrinterName");
PrintTicket printTicket = GetPrintTicket(printQueue);
PrintDialog printDlg = new PrintDialog();
printDlg.PrintQueue = printQueue;
printDlg.PrintTicket = printTicket;
Canvas c = new Canvas();
System.Windows.Shapes.Rectangle r = new System.Windows.Shapes.Rectangle();
r.Width = 100;
r.Height = 100;
r.Fill = new SolidColorBrush(Colors.Red);
Canvas.SetTop(r, 0);
Canvas.SetLeft(r, 0);
c.Children.Add(r);
printDlg.PrintVisual(c, "Description Test");
}
I obtain the correct file that I'm looking for but the function PrintVisual shows a dialog asking for the name of the output file.
Is there any way to set the output file name programatically?
Is there a better way to print WPF objects without showing any dialog to the user?