如何在处理打印请求中提供页面范围

我有一个文档,我要使用下面的 c# 代码将其发送打印


 p.StartInfo = new ProcessStartInfo()

 {

    CreateNoWindow = true,

    WindowStyle = ProcessWindowStyle.Hidden,

    Verb = "print",

    FileName = FileToPrintPath//put the correct path here

            };

 p.Start();

现在,我有一个条件,我想打印从页码2到5. 我怎样才能做到这一点?


慕运维8079593
浏览 170回答 1
1回答

慕的地8271018

我不知道您的问题的直接答案,但您可以使用下面的代码轻松解决这个问题。显示一个对话框并选择页码、份数等,然后查看它在printDialog1.PrinterSettings. 知道格式后,删除对话框代码并将其硬编码为Arguments:using (PrintDialog printDialog1 = new PrintDialog()){    if (printDialog1.ShowDialog() == DialogResult.OK)    {        var info = new ProcessStartInfo(**FILENAME**);        info.Arguments = "\"" + printDialog1.PrinterSettings.PrinterName + "\"";        // Use the debugger a message dialog to see         // contents of printDialog1.PrinterSettings    }}我写了一个快速测试,这里是存储在PrinterSettings:[PrinterSettings Microsoft XPS Document Writer Copies=1 Collate=False Duplex=Simplex FromPage=0 LandscapeAngle=270 MaximumCopies=1 OutputPort=PORTPROMPT: ToPage=0]所以你需要通过FromPage和ToPage:info.Arguments = "\"" + printDialog1.PrinterSettings.PrinterName + "\"" + "FromPage=2 ToPage=5";在您的代码中:p.StartInfo = new ProcessStartInfo(){    CreateNoWindow = true,    WindowStyle = ProcessWindowStyle.Hidden,    Verb = "print",    FileName = FileToPrintPath,//put the correct path here,     Arguments = "\"Printer Name Goes Here\" FromPage=2 ToPage=5";};请不要它们是空格分隔的参数,如果您的打印机名称有空格,则需要将打印机名称放在引号内。
打开App,查看更多内容
随时随地看视频慕课网APP