Hi,
I has codes below to print the rdlc report automatically and it works well.
Currently my codes is create stream for the RDLC and print all the pages together. How can I amend my codes so that everytime the printer print a page, there will be a message box inform them?Code:Sub sbAutoSendToPrinter(ByVal pstrCardMessage As String, ByVal pstrLocalReport As LocalReport) Dim strPrinter As String = "" Dim intCount As Integer = 0 Dim strCardMessage() As String = Split(pstrCardMessage, "|") strPrinter = FnReadstrCardPrinter() If strPrinter <> "" Then trytoprint: ExportCard(pstrLocalReport, strPrinter) Print() Else Throw New ArgumentException("No printer selected!") End If Me.Close() End Sub Private Function CreateStream(ByVal name As String, ByVal fileNameExtension As String, ByVal encoding As Encoding, ByVal mimeType As String, ByVal willSeek As Boolean) As Stream Dim stream As Stream = New MemoryStream() Try m_streams.Add(stream) Catch ex As Exception Throw End Try Return stream End Function ' Export the given report as an EMF (Enhanced Metafile) file. Private Sub ExportCard(ByVal report As LocalReport, ByVal strPrinterName As String) Try Dim deviceInfo As String = "<DeviceInfo>" & _ "<OutputFormat>EMF</OutputFormat>" & _ "<PageWidth>8.9in</PageWidth>" & _ "<PageHeight>11in</PageHeight>" & _ "<MarginTop>0.2in</MarginTop>" & _ "<MarginLeft>0.4in</MarginLeft>" & _ "<MarginRight>0.2in</MarginRight>" & _ "<MarginBottom>0.2in</MarginBottom>" & _ "</DeviceInfo>" Dim warnings As Warning() m_streams = New List(Of Stream)() report.Render("Image", deviceInfo, AddressOf CreateStream, warnings) For Each stream As Stream In m_streams stream.Position = 0 Next Catch ex As Exception Throw End Try End Sub Private Sub Print() Try If m_streams Is Nothing OrElse m_streams.Count = 0 Then Throw New Exception("Error: no stream to print.") End If Dim printDoc As New PrintDocument() If Not printDoc.PrinterSettings.IsValid Then Throw New Exception("Error: cannot find the default printer.") Else AddHandler printDoc.PrintPage, AddressOf PrintPage m_currentPageIndex = 0 printDoc.Print() End If Catch ex As Exception Throw End Try End Sub Private Sub PrintPage(ByVal sender As Object, ByVal ev As PrintPageEventArgs) Try Dim pageImage As New Metafile(m_streams(m_currentPageIndex)) Dim adjustedRect As New Rectangle(ev.PageBounds.Left - CInt(ev.PageSettings.HardMarginX), _ ev.PageBounds.Top - CInt(ev.PageSettings.HardMarginY), _ ev.PageBounds.Width, _ ev.PageBounds.Height) ev.Graphics.FillRectangle(Brushes.White, adjustedRect) ev.Graphics.DrawImage(pageImage, adjustedRect) m_currentPageIndex += 1 ev.HasMorePages = (m_currentPageIndex < m_streams.Count) Catch ex As Exception Throw End Try End Sub
"Msgbox("Please insert Card to print next page!")"


Reply With Quote
Bookmarks