質問


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