1
我想创建方法,打印任何文件到XPS使用其默认应用程序,在我的Windows窗体应用程序。这工作正常,但我无法将目标XPS路径传递给打印机,并且打开文件对话框始终弹出。 任何不使用FindWindow interrop的建议都会有帮助。
谢谢!.NET打印任何文件到文件名为XPS
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. ");
}
}