使用C#更改打印机设置

时间:2018-12-05 17:00:04

标签: c#

我正在尝试使用以下代码更改打印机设置。打印机是共享打印机,我已授予用户更改设置的权限。按下按钮后,它正在打印,但是打印机设置无法正常工作。具体来说,我想用printdoc.PrinterSettings.Copies = 2;打印两份,但实际上只打印一份。

private void button1_Click(object sender, EventArgs e)
{
    string exeFolder = Application.StartupPath;
    string Filepath = Path.Combine(exeFolder, @"Form.pdf");
    Process printjob = new Process();
    printjob.StartInfo.FileName = Filepath;
    printjob.StartInfo.Verb = "Print";
    printjob.StartInfo.CreateNoWindow = true;
    printjob.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
    PrinterSettings ps = new PrinterSettings();
    PrintDocument printdoc= new PrintDocument();
    printdoc.PrinterSettings = ps;
    IEnumerable<PaperSize> paperSizes = ps.PaperSizes.Cast<PaperSize>();
    PaperSize sizeA4 = paperSizes.First<PaperSize>(size => size.Kind == PaperKind.A4);
    printdoc.DefaultPageSettings.PaperSize = sizeA4;
    PaperSource oPSource = new PaperSource();
    oPSource.RawKind = (int)PaperSourceKind.Lower;
    printdoc.DefaultPageSettings.PaperSource = oPSource;
    printdoc.PrinterSettings.Copies = 2;            
    printjob.Start();
}

0 个答案:

没有答案