Thank you for reaching out. This is a known behavior when the SSRS report is rendered incorrectly or when page iteration is not handled properly in the PrintPage event.
Root Cause
The issue occurs because:
- ServerReport.Render("Image", ...) returns only one EMF stream unless a stream callback is used.
- PrintPage is fired once unless e.HasMorePages = True is correctly set.
- pageIndex is not reset or incremented properly.
- Page streams are not generated for all report pages.
As a result, only the first page gets printed.
Recommended Solution:
Step 1: Declare global variables
Private pages As New List(Of Metafile)
Private pageIndex As Integar = 0
Step 2: Render all pages using a stream callback
This ensures every page of the report is rendered
Private Function CreateStream( _
ByVal name As String, _
ByVal extension As String, _
ByVal encoding As System.Text.Encoding, _
ByVal mimetype As String, _
ByVal willSeek As Boolean) As IO.Stream
Dim stream As New IO.MemoryStream()
pages.Add(New Metafile(stream))
Return stream
End function
Step 3: Render report to EMF images
Dim deviceInfo As String =
"<DeviceInfo>" &
" <OutputFormat>EMF</OutputFormat>" &
" <PageWidth>8.3in</PageWidth>" &
" <PageHeight>11.7in</PageHeight>" &
" <MarginTop>0.14in</MarginTop>" &
" <MarginLeft>0.22in</MarginLeft>" &
" <MarginRight>0.22in</MarginRight>" &
" <MarginBottom>0.14in</MarginBottom>" &
"</DeviceInfo>"
pages.Clear()
ReportViewer1.ServerReport.Rendor(
"Image",
deviceInfo,
AddressOf CreateStream,
Nothing
)
For each page As Metafile in pages
page.GetHenhmetafile()
Next
Step 4: Print using PrintDocument
pageIndex = 0
Dim doc As New Printing.PrintDocument()
AddHandler doc.printPage, AddressOf PrintPageHandler
doc.Print()
Step 5: Correct PrintPageHandler(Critical Fix)
Private Sub PrintPageHandler(
ByVal sender As Object,
ByVal e As Printing.PrintPageEventArgs)
Dim page As Metafile = pages(pageIndex)
e.Graphics.DrawImage(
page,
e.PageBounds
)
pageIndex +=1
e.HasMorePages = (pageIndex < pages.Count)
End Sub
This ensures all pages are printed, not just the first one.
Why This works
- SSRS generates one EMF stream per page.
- CreateStream captures all pages
- HasMorePages correctly tells the printer to continue
- PageIndex ensures sequential printing
Please let us know if you require any further assistance we’re happy to help. If you found this information useful, kindly mark this as "Accept Answer".