문제


I am trying to create method that prints any file to XPS using its default aplication, in my Windows forms app. This works fine, but I am unable to pass destination XPS path to the printer and open file dialog always pops out. Any suggestion without using FindWindow interrop will be helpfull.
Thank you!

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. "); 
        }
    }
도움이 되었습니까?

해결책

I've found commerical solution that works. It installs its own driver and provides .NET api for setting file name. It converts directly to PDF, but then can be exported to XPS. Link here: Amyuni PDF Converter

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top