Print Problem - Image Overlap using Print Document - Print Page Event

Leon

Member
Joined
Sep 23, 2005
Messages
8
Programming Experience
10+
I am printing images using the e.Graphics.Drawimage() function in the printpage event.

The problem is that when attempting to print multiple images, the images overlap.

That is, when I attempt to print 3 images on 3 separate pages, I get 2 pages with 1 image on page 1 and 2 images on page 2. I should get 3 pages.


First, I set "HasmorePages=true", then after my counter variables reaches the desired number of images that I want to print, then I set "HasmorePages=false".

I there something special about printing images.

WHY DO MY IMAGES OVERLAP?

WHY DO I NOT GET 3 IMAGES PRINTING ON 3 PAGES.
 
Last edited:
I would bet that you are doing this:
checking out the pageNum you are increasing its value at the wrong place and at the wrong time JK :D

This is how it should look like:

VB.NET:
{...}
[color=#0000ff]Static[/color] pageNum [color=#0000ff]As [/color][color=#0000ff]Integer [color=seagreen]'by default it is null[/color]
 
[/color]e.Graphics.DrawString("PAGE " & pageNum [color=red][b]+ 1[/b][/color], prFont, Brushes.Black, 700, 1050)
 
[color=#008000]'more printing statements here
 
[/color]pageNum = pageNum + 1  [color=green]'this is where your bug is i beleive[/color]
 
[color=#0000ff]If[/color] pageNum < 3 [color=#0000ff]Then [color=green]'if rest of the code is doing fine this should print three pages there[/color]
 
[/color]e.HasMorePages = [color=#0000ff]True
 
[/color][color=#0000ff]Else
 
[/color]e.HasMorePages = [color=#0000ff]False
 
[/color][color=#0000ff]End [/color][color=#0000ff]If


[/color]HTH
Regards ;)
 
Problem with PrintDocument Text Overlap

This is the code for my Printpage event (see below). In this case, I get 2 pages (which is correct).

However, on Page 1, I get "This is page 12" but the 1 and 2 overlap.

And on Page 2, I get "This is page 34" but the 3 and 4 overlap.

So, the '1' and the '2' and '3' and the '4' are not really next to each other as I typed it, but instead the '2' is on top of the '1' and the '4' is on top of the '3'

WHY.


The correct text should read:

Page 1 "This is page 1"

Page 2 "This is page 2"
_________________________________________________________
Private Sub pdoc_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles pdoc.PrintPage

Static z As Integer

e.Graphics.DrawString("This is page " & z + 1, printFont, Brushes.Black, 1, 1)


z += 1
If z < 3 Then

e.HasMorePages = True

Else

e.HasMorePages = False

End If

End Sub

 
CORRECTION


In reference to the previous post.

What seems to be happening is, It looks like 4 pages (images) are being generated.


Two pages are on Page 1 and two pages are on Page 2

Pages 1 and 2 overlap on Page 1 and

Pages 3 and 4 overlap on Page 2.

In this example, it should only be generating two pages, with 1 page on each page.
 
This is the code that is producing the 4 pages overlapped onto 2 pages.

________________________________________________________

PrivateSub pdoc_PrintPage(ByVal sender AsObject, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles pdoc.PrintPage

Static z AsInteger

e.Graphics.DrawString("This is page " & z + 1, printFont, Brushes.Black, 1, 1)


z += 1
If z < 3 Then

e.HasMorePages = True

Else

e.HasMorePages = False

EndIf

EndSub


 
Observation:


The printpage event seems be to firing twice on each pass even after "HasMorePages=false"

Is this a "bug".
 
Print Numbered Pages

Nah ... it is not bug at all ! There must be something that you are doing bad

However this is an example (very basic) and it works absolutely fine for me ... give it a try !!!
VB.NET:
[size=2][color=#0000ff]Private [/color][/size][size=2][color=#0000ff]Sub[/color][/size][size=2] Button1_Click([/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] sender [/size][size=2][color=#0000ff]As[/color][/size][size=2] System.Object, [/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] e [/size][size=2][color=#0000ff]As[/color][/size][size=2] System.EventArgs) [/size][size=2][color=#0000ff]Handles[/color][/size][size=2] Button1.Click
 
PrintDocument1.Print()
 
[/size][size=2][color=#0000ff]End [/color][/size][size=2][color=#0000ff]Sub
 
[/color][/size][size=2][color=#0000ff]Private[/color][/size][size=2][color=#0000ff]Sub[/color][/size][size=2] PrintDocument1_PrintPage([/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] sender [/size][size=2][color=#0000ff]As [/color][/size][size=2][color=#0000ff]Object[/color][/size][size=2], [/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] e [/size][size=2][color=#0000ff]As[/color][/size][size=2] System.Drawing.Printing.PrintPageEventArgs) [/size][size=2][color=#0000ff]Handles[/color][/size][size=2] PrintDocument1.PrintPage
 
[/size][size=2][color=#0000ff]Static[/color][/size][size=2] pageNum [/size][size=2][color=#0000ff]As [/color][/size][size=2][color=#0000ff]Integer
 
[/color][/size][size=2][color=#0000ff]Dim[/color][/size][size=2] prFont [/size][size=2][color=#0000ff]As [/color][/size][size=2][color=#0000ff]New[/color][/size][size=2] Font("Verdana", 12, GraphicsUnit.Point)
 
e.Graphics.DrawString("PAGE " & pageNum + 1, prFont, Brushes.Black, 600, 1050)
 
e.Graphics.DrawString("Printing with VB.NET", prFont, Brushes.Black, 20, 20)
 
[/size][size=2][color=#008000]' add more printing statements here
 
[/color][/size][size=2]pageNum = pageNum + 1
 
[/size][size=2][color=#0000ff]If[/color][/size][size=2] pageNum < 3 [/size][size=2][color=#0000ff]Then
 
[/color][/size][size=2]e.HasMorePages = [/size][size=2][color=#0000ff]True
 
[/color][/size][size=2][color=#0000ff]Else
 
[/color][/size][size=2]e.HasMorePages = [/size][size=2][color=#0000ff]False
 
[/color][/size][size=2][color=#0000ff]End [/color][/size][size=2][color=#0000ff]If
 
[/color][/size][size=2][color=#0000ff]End [/color][/size][size=2][color=#0000ff]Sub
 
[/color][/size]


Ignore the code and run the project attached below

HTH
Regards ;)
 

Attachments

  • NumberedPages.zip
    22.9 KB · Views: 61
Back
Top