This is a migrated thread and some comments may be shown as answers.

Printable Panel Header and Footer

2 Answers 134 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
William
Top achievements
Rank 1
William asked on 17 Jun 2015, 08:37 PM

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 Answers, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 18 Jun 2015, 02:50 PM
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
0
William
Top achievements
Rank 1
answered on 18 Jun 2015, 03:27 PM
Perfect.   Thanks for the quick reply!
Tags
General Discussions
Asked by
William
Top achievements
Rank 1
Answers by
Hristo
Telerik team
William
Top achievements
Rank 1
Share this question
or