1 回答

TA貢獻(xiàn)1796條經(jīng)驗(yàn) 獲得超4個(gè)贊
我不知道您的問題的直接答案,但您可以使用下面的代碼輕松解決這個(gè)問題。顯示一個(gè)對(duì)話框并選擇頁碼、份數(shù)等,然后查看它在printDialog1.PrinterSettings. 知道格式后,刪除對(duì)話框代碼并將其硬編碼為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
}
}
我寫了一個(gè)快速測(cè)試,這里是存儲(chǔ)在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";
};
請(qǐng)不要它們是空格分隔的參數(shù),如果您的打印機(jī)名稱有空格,則需要將打印機(jī)名稱放在引號(hào)內(nèi)。
- 1 回答
- 0 關(guān)注
- 199 瀏覽
添加回答
舉報(bào)