Question

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).

The line

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

has no effect.

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

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.

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

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

Thanks, Adam

Was it helpful?

Solution

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!)

This 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();
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top