[RESOLVED] RDLC Auto Print By Page
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: [RESOLVED] RDLC Auto Print By Page

Hybrid View

  1. #1
    Join Date
    Jan 2009
    Posts
    161

    [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!")"

  2. #2
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    15,002

    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?
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Jan 2009
    Posts
    161

    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.

  4. #4
    Join Date
    Jan 2009
    Posts
    161

    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center