我正在尝试在我的 Windows 窗体应用程序中创建使用默认应用程序将任何文件打印到 XPS 的方法。这工作正常,但我无法将目标 XPS 路径传递给打印机,并且总是弹出打开文件对话框。任何不使用 FindWindow interrop 的建议都会有所帮助。
谢谢!
private void PrintXps(string printFilePath, string destinationXps){
var printJob = new Process();
printJob.StartInfo.FileName = filePath;
printJob.StartInfo.UseShellExecute = true;
printJob.StartInfo.Verb = "printto";
printJob.StartInfo.CreateNoWindow = true;
printJob.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
var xps = PrinterSettings.InstalledPrinters.Cast<string>().First(p => p.ToLower().Contains("xps"));
printJob.StartInfo.Arguments = string.Format("\"{0}\"", xps);
printJob.StartInfo.WorkingDirectory = Path.GetDirectoryName(filePath);
try
{
printJob.Start();
printJob.WaitForExit();
}
catch (Win32Exception ex)
{
MessageBox.Show("File is not supported. ");
}
}