Is there anyway to specify a PrintTo printer when spawning a process?

前端 未结 2 1791
陌清茗
陌清茗 2020-12-30 08:12

What I Have

I am currently writing a program which takes a specified file and the performs some action with it. Currently it opens it, and/or attaches it to an ema

2条回答
  •  青春惊慌失措
    2020-12-30 08:41

    The following works for me (tested with *.doc and *.docx files)

    the windows printto dialog appears by using the "System.Windows.Forms.PrintDialog" and for the "System.Diagnostics.ProcessStartInfo" I just take the selected printer :)

    just replace the FILENAME with the FullName (Path+Name) of your Office file. I think this will also work with other files...

    // Send it to the selected printer
    using (PrintDialog printDialog1 = new PrintDialog())
    {
        if (printDialog1.ShowDialog() == DialogResult.OK)
        {
            System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo(**FILENAME**);
            info.Arguments = "\"" + printDialog1.PrinterSettings.PrinterName + "\"";
            info.CreateNoWindow = true;
            info.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
            info.UseShellExecute = true;
            info.Verb = "PrintTo";
            System.Diagnostics.Process.Start(info);
        }
    }
    

提交回复
热议问题