-
January 10th, 2013, 09:13 PM
#1
[RESOLVED] RDLC Auto Print By Page
Hi,
I has codes below to print the rdlc report automatically and it works well.
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
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?
"Msgbox("Please insert Card to print next page!")"
-
January 10th, 2013, 10:22 PM
#2
Re: RDLC Auto Print By Page
Because they only have to CLICK the message box, not insert a card (or whatever). Re-think your question. What CARD are you talking about?
-
January 10th, 2013, 10:59 PM
#3
Re: RDLC Auto Print By Page
This is because we are printing the pages into a card printer, so everytime they print a page, they are required to insert Customer Card into the printer to print it. That why I need to prompt a message box informing them to insert Customer Card.
-
January 11th, 2013, 01:49 AM
#4
Re: RDLC Auto Print By Page
I had found the solution.Thanks.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|