duplex printing

RonR

Well-known member
Joined
Nov 23, 2007
Messages
82
Programming Experience
5-10
I am trying to print in duplex mode. when I send 2 pages to the printer it will print the first page on BOTH sides of the first sheet printed and then it prints
the 2nd page.

this seems strange.


has anybody else had this problem or do you have any idea what the problem may be?
 
Thread moved to Printing forum since this is a printing topic. It's a fairly obvious choice of which appropriate forum to post in.

Do you have code too? Like a small snippet that should reproduce the problem if I run it?
 
the whole thing is tied to my datagridview.

sorry, i did not see a printing section.


Thread moved to Printing forum since this is a printing topic. It's a fairly obvious choice of which appropriate forum to post in.

Do you have code too? Like a small snippet that should reproduce the problem if I run it?
 
Duplex printing & loop printing

When I print manual the duplex works fine but when I run printing thru a loop there are major problems.

this requires a duplex printer but some of the problems may show in a regular printer.

I get 9 printouts instead of 3 in loop printing.


could someone take a look??
 

Attachments

  • demo1.zip
    16.5 KB · Views: 50
Last edited by a moderator:
Printing topic, thread moved to Printing forum. Please post in appropriate forum. Didn't I tell you this yesterday too? The heck, why not merge while at it, you're basically asking the same question.

I may have a look when I can print to a duplex printer, but in theory your calls are identical, "manual" does one print job, "loop" does 3 print jobs.
 
VB.NET:
Option Strict On
Option Explicit On

Imports System.IO
Imports System.Drawing.Printing
Imports System
Imports System.Drawing

Public Class Form1

    Private TotalToPrint As Integer = 0
    Private iPageNumber As Integer = 0

    Private blnPrintPreview As Boolean = False
    Private pdPrinter As PrintDocument
    Private ppvwPrinter As PrintPreviewDialog

    Private Sub Button1_CLick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        pdPrinter = New PrintDocument
        ppvwPrinter = New PrintPreviewDialog
        AddHandler pdPrinter.BeginPrint, AddressOf TestDuplex_BeginPrint
        AddHandler pdPrinter.PrintPage, AddressOf TestDuplex_PrintPage
        AddHandler pdPrinter.EndPrint, AddressOf TestDuplex_EndPrint

        If blnPrintPreview = True Then
            ppvwPrinter.Document = pdPrinter
            ppvwPrinter.Width = Screen.PrimaryScreen.Bounds.Width
            ppvwPrinter.Height = Screen.PrimaryScreen.Bounds.Height
            ppvwPrinter.PrintPreviewControl.Zoom = 0.5
            ppvwPrinter.ShowDialog()
        Else
            pdPrinter.PrintController = New StandardPrintController 'silent printing
            pdPrinter.Print()
        End If

        RemoveHandler pdPrinter.BeginPrint, AddressOf TestDuplex_BeginPrint
        RemoveHandler pdPrinter.PrintPage, AddressOf TestDuplex_PrintPage
        RemoveHandler pdPrinter.EndPrint, AddressOf TestDuplex_EndPrint
        pdPrinter.Dispose()
        ppvwPrinter.Dispose()
    End Sub

    Private Sub TestDuplex_BeginPrint(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintEventArgs)
        pdPrinter.DocumentName = "Test Duplex"
        pdPrinter.OriginAtMargins = True
        pdPrinter.DefaultPageSettings.Landscape = True
        pdPrinter.PrinterSettings.Duplex = Printing.Duplex.Vertical
        pdPrinter.PrinterSettings.Copies = 2

        TotalToPrint = 3
        iPageNumber = 0
    End Sub

    Private Sub TestDuplex_PrintPage(ByVal sender As System.Object, ByVal e As PrintPageEventArgs)
        iPageNumber += 1

        e.Graphics.PageUnit = GraphicsUnit.Millimeter

        e.Graphics.DrawString("PAGE " & iPageNumber.ToString, New Font("Arial", 8, FontStyle.Bold), Brushes.Black, 20, 20)

        If iPageNumber < TotalToPrint Then
            e.HasMorePages = True
        Else
            e.HasMorePages = False
        End If
    End Sub

    Private Sub TestDuplex_EndPrint(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintEventArgs)
        'clean up here if necessary
    End Sub

End Class

On my duplex printer, this gives me :-

First page, with "PAGE 1" on the front and "PAGE 2" on the back
Second page, with "PAGE 3" on the front
Third page, with "PAGE 1" on the front and "PAGE 2" on the back
Fourth page, with "PAGE 3" on the front

In other words, correctly printed.
 
Last edited:
Thanks for all the code! I will copy & paste it for future use.

I discovered that the pagehandler seems to run it's own loop.

I now have my code running perfect(with a couple of modifications).
 
Back
Top