Printable Panel Header and Footer

3 posts, 0 answers
  1. Jim
    Jim avatar
    15 posts
    Member since:
    Oct 2012

    Posted 17 Jun 2015 Link to this post

    I had no trouble creating a printable panel control using the documentation provided.  However if I add header and footer height and text to the radprintdocument in the control, the panel is printed overtop of the header.  How can I change so this doesn't happen?  (code for print preview of printable panel pnlCashReceiptsSummary and of custom control below)

     

     Code I'm using for print preview:

    Dim doc As New RadPrintDocument()
    doc.DefaultPageSettings.Landscape = True

    doc.HeaderHeight = 100
    doc.HeaderFont = New Font("Arial", 14, FontStyle.Bold)
    doc.RightHeader = "AAAA"
    doc.LeftHeader = "[Date Printed]"
    doc.FooterHeight = 100
    doc.FooterFont = New Font("Arial", 12)
    doc.LeftFooter = GlobalVariables.CurrentDealer.Dealer_Fxd.DealerCode

     pnlCashReceiptsSummary.PrintPreview(doc)

     

    My Control :  

     Imports Telerik.WinControls.UI
    Imports System.Drawing.Printing

    Public Class PrintablePanel
    Inherits RadPanel
    Implements IPrintable


    Public Function BeginPrint(sender As RadPrintDocument, args As PrintEventArgs) As Integer Implements IPrintable.BeginPrint

    Return 1
    End Function

    Public Function EndPrint(sender As RadPrintDocument, args As PrintEventArgs) As Boolean Implements IPrintable.EndPrint
    Return True
    End Function

    Public Function GetSettingsDialog(document As RadPrintDocument) As Form Implements IPrintable.GetSettingsDialog
    Return New PrintSettingsDialog(document)
    End Function

    Public Function PrintPage(pageNumber As Integer, sender As RadPrintDocument, args As PrintPageEventArgs) As Boolean Implements IPrintable.PrintPage
    Dim bmp As New Bitmap(Me.Width, Me.Height)
    Me.DrawToBitmap(bmp, New Rectangle(Point.Empty, Me.Size))
    args.Graphics.DrawImage(bmp, Point.Empty)
    Return False
    End Function

    Public Sub Print(ByVal doc As RadPrintDocument)
    doc.AssociatedObject = Me
    doc.Print()
    End Sub

    Public Sub PrintPreview(ByVal doc As RadPrintDocument)
    doc.AssociatedObject = Me
    Dim dialog As New RadPrintPreviewDialog(doc)
    dialog.ThemeName = Me.ThemeName
    dialog.ShowDialog()
    End Sub

    Private Function CreatePrintDocument() As RadPrintDocument
    Dim doc As New RadPrintDocument()
    doc.AssociatedObject = Me
    Return doc
    End Function
    End Class

     

  2. Hristo Merdjanov
    Admin
    Hristo Merdjanov avatar
    710 posts

    Posted 18 Jun 2015 Link to this post

    Hello Jim,

    Thank you for writing.

    In order to achieve the desired behavior, you would need to draw the image with a slight offset to the left and to the top. I have slightly changed your implementation of the printable panel, so that the sizes of the header and footer are respected as well as the margins of the document. Please check the code below: 
    Public Class PrintablePanel
        Inherits RadPanel
        Implements IPrintable
     
        Public Function BeginPrint(sender As RadPrintDocument, args As PrintEventArgs) As Integer Implements IPrintable.BeginPrint
     
            Return 1
        End Function
     
        Public Function EndPrint(sender As RadPrintDocument, args As PrintEventArgs) As Boolean Implements IPrintable.EndPrint
            Return True
        End Function
     
        Public Function GetSettingsDialog(document As RadPrintDocument) As Form Implements IPrintable.GetSettingsDialog
            Return New PrintSettingsDialog(document)
        End Function
     
        Public Function PrintPage(pageNumber As Integer, sender As RadPrintDocument, args As PrintPageEventArgs) As Boolean Implements IPrintable.PrintPage
            Dim offsetTop = sender.HeaderHeight + sender.Margins.Top
            Dim offsetLeft = sender.FooterHeight + sender.Margins.Left
     
            Dim bmp As New Bitmap(Me.Width, Me.Height)
            Me.DrawToBitmap(bmp, New Rectangle(Point.Empty, Me.Size))
            args.Graphics.DrawImage(bmp, offsetTop, offsetLeft)
            Return False
        End Function
     
        Public Sub Print(ByVal doc As RadPrintDocument)
            doc.AssociatedObject = Me
            doc.Print()
        End Sub
     
        Public Sub PrintPreview(ByVal doc As RadPrintDocument)
            doc.AssociatedObject = Me
            Dim dialog As New RadPrintPreviewDialog(doc)
            dialog.ThemeName = Me.ThemeName
            dialog.ShowDialog()
        End Sub
     
        Private Function CreatePrintDocument() As RadPrintDocument
            Dim doc As New RadPrintDocument()
            doc.AssociatedObject = Me
            Return doc
        End Function
    End Class

    I am also sending you a screenshot of the result on my end.

    I hope this helps. Should you have further questions please do not hesitate to write back.

    Regards,
    Hristo Merdjanov
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Jim
    Jim avatar
    15 posts
    Member since:
    Oct 2012

    Posted 18 Jun 2015 Link to this post

    Perfect.   Thanks for the quick reply!
Back to Top