I want to print a PDF file (url) from windows application without opening print dialog.
I have tried the code bellow
string pdfUrl="mysite.com/test.pdf";
string printerName = "Microsoft Print To PDF";
using (var client = new System.Net.WebClient())
{
client.Proxy.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
client.DownloadFile(pdfUrl, filePath);
}
ProcessStartInfo info = new ProcessStartInfo();
info.Verb = "print";
info.FileName = filePath;
info.Arguments = "\"" + printerName + "\"";
info.UseShellExecute = true;
info.CreateNoWindow = true;
info.WindowStyle = ProcessWindowStyle.Hidden;
info.WorkingDirectory = Path.GetDirectoryName(filePath);
Process p = new Process();
p.StartInfo = info;
p.Start();
//p.WaitForInputIdle();
//System.Threading.Thread.Sleep(3000);
//if (false == p.CloseMainWindow())
// p.Kill();
but getting error in p.Start(); bellow System.ComponentModel.Win32Exception: No application is associated with the specified file for this operation
What is missing?
Please suggest how to solve this.