1 回答
TA贡献1796条经验 获得超4个赞
我不知道您的问题的直接答案,但您可以使用下面的代码轻松解决这个问题。显示一个对话框并选择页码、份数等,然后查看它在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";
};
请不要它们是空格分隔的参数,如果您的打印机名称有空格,则需要将打印机名称放在引号内。
- 1 回答
- 0 关注
- 167 浏览
添加回答
举报