C # forces a simplex job to print (by default, Duplex is a printer)

Problem
1. Our client has a network printer that is configured to print in duplex (this cannot be changed).
2. We must print A4 sheets on this printer, but it should not be in duplex mode, since the labels bypass the rollers and become dirty.
3. When we print our marks, the print job is still in duplex mode (checked by checking the PCL output by printing to a file).

Line

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

has no effect.

How to make a page print in Simplex?

Our code
We print to an A4 printer using the .Net PrintDocument / PrintController classes, as shown below. This code is from a test application that can reproduce the problem with a simple example.

We have our own PrintDocument class, which:
a) Sets print options in OnQueryPageSettings

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

b) Creates 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;
}

To drop this, we instantiate our PrintDocument, assign it a 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();
    }
}

Thanks Adam

+3
source share
1 answer

Setting the PrinterSettings.Duplex property in OnQueryPageSettings is not affected, you need to set this property before calling Print (). (It seems obvious, now I'm thinking about it!)

It works:

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();
    }
}
+2
source

All Articles