I need to print a file using sumatraPdf, but at the always shows up the window to specify the file name and directory of the output. How can i do it automatically in C#.? Any ideas?
var printerName = "Microsoft Print to PDF";
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = "SumatraPDF.exe";
proc.StartInfo.Arguments = "-print-to " '"' printerName '"' " C:\\ttt.pdf";
proc.StartInfo.RedirectStandardError = false;
proc.StartInfo.RedirectStandardOutput = false;
proc.StartInfo.UseShellExecute = true;
proc.Start();
proc.WaitForExit();
CodePudding user response:
I support SumatraPDF which uses no additional print control beyond the most basic.
Default printer settings are queried and modified for paper/paperkind formats with a few other passthroughs.
Please do not use -silent to suppress error dialogs, it is best for error conditions that the user reports them to you.
So to answer your direct question, the rendering passthrough goes unchanged to the printing port driver (warts and all), where MSPrint2PDF/XPS includes a port prompter device (PORTPROMPT:)
So it is a Windows "Feature" that needs to be bypassed, by not use the PORTPROMPT: device and one way I describe how to alter Windows Processing is shown here
https://stackoverflow.com/a/73514686/10802527
Print to PDF with powershell while suppressing the "Save As" Prompt