C# 强制打印作业为 Simplex(打印机默认为 Duplex) [英] C# force print job to be Simplex (printer default is Duplex)

查看:180
本文介绍了C# 强制打印作业为 Simplex(打印机默认为 Duplex)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题
1. 我们的客户有一台网络打印机,该打印机配置为以双面打印(这无法更改).
2. 我们必须在这台打印机上打印 A4 张标签,但它不能处于双面模式,因为标签会绕着滚轴旋转并弄脏.
3. 当我们打印标签时,打印作业仍处于双面模式(通过打印到文件检查 PCL 输出来验证).

The Problem
1. Our customer has a networked printer that is configured to print in Duplex (this cannot be changed).
2. We must print A4 sheets of labels to this printer but it must not be in Duplex mode as the labels go round the rollers and foul up.
3. When we print our labels the print job still is in Duplex mode (verified by examining the PCL output by printing to file).

线

e.PageSettings.PrinterSettings.Duplex = Duplex.Simplex;  

没有效果.

我们如何强制以 Simplex 打印页面?

How do we force the page to be printed in Simplex?

我们的代码
我们正在使用 .Net PrintDocument/PrintController 类打印到 A4 打印机,如下所示.此代码来自一个测试应用,可以通过一个简单的示例重现该问题.

Our Code
We are printing to an A4 printer using the .Net PrintDocument / PrintController classes, as shown below. This code is from a test app that can reproduce the issue with a simple example.

我们有一个自定义的 PrintDocument 类:
a) 在 OnQueryPageSettings 中设置打印设置

We have a custom PrintDocument class that:
a) Sets the printing settings in OnQueryPageSettings

protected override void OnQueryPageSettings(QueryPageSettingsEventArgs e)
{
    // This setting has no effect
    e.PageSettings.PrinterSettings.Duplex = Duplex.Simplex;
}

b) 在 OnPrintPage 方法中生成页面内容:

b) Generates the page content in the OnPrintPage method:

protected override void OnPrintPage(PrintPageEventArgs e)
{
    Graphics g = e.Graphics;

    int fs = 12;
    FontStyle style = FontStyle.Regular;
    Font baseFont = new Font("Arial", fs, style);

    PointF pos = new PointF(10, 10);

    g.DrawString("This is a test page", baseFont, Brushes.Black, pos);

    e.HasMorePages = false;
}

为此,我们创建一个 PrintDocument 实例,将其分配给 StandardPrintController 并调用 Print():

To kick this off we create an instance of our PrintDocument, assign it the StandardPrintController and call Print():

void DoPrint()
{
    MyPrintDocument mydoc = new MyPrintDocument();

    PrinterSettings ps = ShowPrintDialog();
    if (ps != null)
    {
        mydoc.PrinterSettings = ps;
        StandardPrintController cont = new StandardPrintController();
        mydoc.PrintController = cont;
        mydoc.Print();
    }
}

谢谢,亚当

推荐答案

在 OnQueryPageSettings 上设置 PrinterSettings.Duplex 属性没有效果,需要在调用 Print() 之前设置该属性.(现在想起来似乎很明显!)

Setting the PrinterSettings.Duplex property on OnQueryPageSettings has no effect, you need to set this property before calling Print(). (It seems obvious now I think about it!)

这有效:

void DoPrint()
{
    MyPrintDocument mydoc = new MyPrintDocument();

    PrinterSettings ps = ShowPrintDialog();
    if (ps != null)
    {
        ps.Duplex = Duplex.Simplex; // This works

        mydoc.PrinterSettings = ps;
        StandardPrintController cont = new StandardPrintController();
        mydoc.PrintController = cont;
        mydoc.Print();
    }
}

这篇关于C# 强制打印作业为 Simplex(打印机默认为 Duplex)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆