Hi, I've just managed it. Please take a look at the following code and see what you think. It was pulled from a lot of sources and there has been alot of experimentation so there will be lots of loose ends(and because I don't understand much of it) I'm sure there is plenty wrong with it, let me know what you think.
Imports
System.IO
Imports
System.Data
Imports
System.Text
Imports
System.Drawing.Imaging
Imports
System.Drawing.Printing
Imports
System.Collections.Generic
Imports
Microsoft.Reporting.WinForms
Public
Class clsPrintReport_PickingList
Implements IDisposable
Private _Printer As String
Dim iPageCount As Integer
Dim Report As ReportViewer
Public Property pPrinter() As String
Get
Return _Printer
End Get
Set(ByVal value As String)
_Printer = value
End Set
End Property
Private m_currentPageIndex As Integer
Private m_streams As IList(Of Stream)
Private _Rendered As Byte()
Private Sub PrintPage(ByVal sender As Object, ByVal ev As PrintPageEventArgs)
Try
'm_stream.Position = 0
Dim pageImage As New Metafile(m_streams(m_currentPageIndex))
ev.Graphics.DrawImage(pageImage, ev.PageBounds)
m_currentPageIndex += 1
ev.HasMorePages = (m_currentPageIndex < m_streams.Count)
Catch ex As Exception
fnHandleError(ex,
"clsPrintReport_PickingList.PrintPage")
End Try
End Sub
Private Sub Print()
Try
If m_streams Is Nothing Or m_streams.Count = 0 Then
Return
End If
Dim printDoc As New PrintDocument()
printDoc.PrinterSettings.PrinterName = _Printer
If Not printDoc.PrinterSettings.IsValid Then
Dim msg As String = String.Format("Can't find printer ""{0}"".", _Printer)
Console.WriteLine(msg)
Return
End If
AddHandler printDoc.PrintPage, AddressOf PrintPage
printDoc.Print()
Catch ex As Exception
fnHandleError(ex,
"clsPrintReport_PickingList.Print")
End Try
End Sub
Private Sub Render(ByVal Report As ServerReport)
Dim warnings As Warning() = Nothing
Dim streamids As String() = Nothing
Dim mimeType As String = Nothing
Dim encoding As String = Nothing
Dim extension As String = Nothing 'Nothing
Dim deviceInfo As String
Dim Format As String = "Image"
deviceInfo = _
"<DeviceInfo>" + _
" <OutputFormat>EMF</OutputFormat>" + _
" <PageWidth>8.5in</PageWidth>" + _
" <PageHeight>11in</PageHeight>" + _
" <MarginTop>0.25in</MarginTop>" + _
" <MarginLeft>0.25in</MarginLeft>" + _
" <MarginRight>0.25in</MarginRight>" + _
" <MarginBottom>0.25in</MarginBottom>" + _
"</DeviceInfo>"
Dim streamid As String
Dim myParameters(0) As ReportParameter
Try
'Parameters = Nothing
m_streams =
New List(Of Stream)()
'm_stream = New FileStream("..\..\" + "Render", FileMode.Create)
myParameters(0) =
New ReportParameter("OrderNo", 63263, False)
Report.SetParameters(myParameters)
_Rendered = Report.Render(Format, deviceInfo, mimeType, encoding, extension, streamids, warnings)
Dim stream As New FileStream("..\..\" + "Main", FileMode.Create)
stream.Write(_Rendered, 0,
CInt(_Rendered.Length))
m_streams.Add(stream)
'stream.Close()
'_Rendered = Report.RenderStream(Format, streamids(0), deviceInfo, mimeType, encoding)
For Each streamid In streamids
_Rendered = Report.RenderStream(Format, streamid, deviceInfo, mimeType, encoding)
stream =
New FileStream("..\..\" + streamid, FileMode.Create)
stream.Write(_Rendered, 0,
CInt(_Rendered.Length))
m_streams.Add(stream)
'stream.Close()
Next
For Each stream In m_streams
stream.Position = 0
Next
Catch ex As Exception
fnHandleError(ex,
"clsPrintReport_PickingList.Render")
End Try
End Sub
Public Sub Run()
Try
Report.ServerReport.ReportPath =
"/Despatch Reports/PickingList_Pallets"
Report.ServerReport.ReportServerUrl =
New Uri("http://itsdeesr02/reportserver")
Dim myParameters(0) As ReportParameter
myParameters(0) =
New ReportParameter("OrderNo", 63263, False)
Report.ServerReport.SetParameters(myParameters)
Report.RefreshReport()
Render(Report.ServerReport)
m_currentPageIndex = 0
Print()
Catch ex As Exception
fnHandleError(ex,
"clsPrintReport_PickingList.Run")
End Try
End Sub
Public Overloads Sub Dispose() Implements IDisposable.Dispose
If Not (m_streams Is Nothing) Then
Dim stream As Stream
For Each stream In m_streams
stream.Close()
Next
m_streams =
Nothing
End If
End Sub
Public Sub New()
Report =
New ReportViewer
End Sub
End
Class