Printing with the PrintPreviewDialog only outputs the last page

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi there,

I am using the PrintPreviewDialog control to print a document.

Pages get added on the PrintDocument_PrintPage event using HasMorePages=True
and this way a print document is created, with all my pages (11 in this case).

The preview shows all 11 pages of this particular print document beatifully.
Everything looks great until I click print....

When I click the print button, only the last page is actually printed - what
happened to pages 1-10?!?

Am I missing something obvious here?

Many thanks,

David
 
Hi David,

Do you use StreamReader to read the lines of a document in the
PrintDocument_PrintPage event handler?

If so, the reason of your problem may be that the current stream position
is already at the end of the stream when you click the Print toolbar button
within the PrintPreviewDialog, because the StreamReader has read to the end
after you show the PrintPreviewDialog.

To solve this problem, you may close the current StreamReader and re-new
the StreamReader in the PrintDocument_PrintPage event handler when the
PrintPageEventArgs.HasMorePages property is set to false.

Hope this helps.
If you have anything unclear, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Linda,

We are not using a StreamReader. I am using a third-party toolkit to print.
Here is the code which does the printing: -

Private Sub printDocument_PrintPage(ByVal sender As Object, ByVal e As
PrintPageEventArgs) Handles _printDocument.PrintPage
' see what page number we require and load that page
Dim pageNumber As Long = _printPages(_currentPrintPage)
Dim image As RasterImage = _rasterCodecs.Load(_viewerFilename, 0,
CodecsLoadByteOrder.BgrOrGrayOrRomm, pageNumber, pageNumber)
' find the image size in pixels at this resolution
Dim destRectangle As New Rectangle(0, 0, _
CType((CType(image.ImageWidth, Single) / CType(image.XResolution,
Single) * 100.0F), Integer), _
CType((CType(image.ImageHeight, Single) /
CType(image.YResolution, Single) * 100.0F), Integer))
' paint the image onto the printer
Dim rasterPaintProperties As RasterPaintProperties =
rasterPaintProperties.Default
rasterPaintProperties.PaintEngine = RasterPaintEngine.GdiPlus
image.Paint(e.Graphics, Rectangle.Empty, Rectangle.Empty,
destRectangle, e.MarginBounds, rasterPaintProperties)
' see if we need more pages
If _currentPrintPage < _printPages.GetLength(0) - 1 Then
_currentPrintPage += 1
e.HasMorePages = True
Else
e.HasMorePages = False
End If
End Sub

As you can see, it uses the e.Graphics object to do the painting (from the
third party imaging toolkit)

If the PrintDocument has all the pages in it, and the preview shows them -
why does it not print them all - what else happens at this stage?

Many thanks,

David
 
OK....

Thanks to Linda's comment, I realised that PrintDocument fires the PrintPage
events twice - once when you preview the document, and once when you click
the print button. Resetting my counter to zero when HASMOREPAGES=FALSE solved
the problem.

Once again, thanks Linda....
 
Back
Top