Using XtraPrinting library, we can achieve the following at runtime while Printing/Exporting a Control:
add additional information to the report; add a report header; specify a page header or footer; specify the paper size, margins, orientation, etc.
For this we have to import two namespaces:
Imports System.Drawing
Imports DevExpress.XtraPrinting
The code below demonstrates how to a create a report with DevExpress Gridcontrol and
Generate the Report Header, Set the Paper Format, and
Add Custom Information to the Report at runtime using XtraPrinting library .
Let us assume that the name of the gridcontrol is “myGridControl”
' Create a PrintingSystem component.
Dim printingSystem As New DevExpress.XtraPrinting.PrintingSystem
Dim link As New DevExpress.XtraPrinting.PrintableComponentLink(printingSystem)
'Specify the control to be printed.
link.Component = gridControl
'Set the paper format.
link.PaperKind = System.Drawing.Printing.PaperKind.A4
'Add Custom Information
link.Landscape = True
link.VerticalContentSplitting = DevExpress.XtraPrinting.VerticalContentSplitting.Smart
link.Margins.Bottom = 100
link.Margins.Top = 100
link.Margins.Left = 10
link.Margins.Right = 10
'Subscribe to the CreateReportHeaderArea event used to generate the report header.
AddHandler link.CreateReportHeaderArea, AddressOf link_CreateReportHeaderArea
' Generate the report.
link.CreateDocument()
' Show the report.
link.ShowPreview()
' to export the report to a PDF file
link.PrintingSystem.ExportToPdf("c:\gridcontrol.pdf")
'event used to generate the report header.
Private Shared Sub link_CreateReportHeaderArea(ByVal sender As System.Object, ByVal e As CreateAreaEventArgs) Dim reportHeader As String = "Report Header"
e.Graph.StringFormat = New BrickStringFormat(StringAlignment.Center)
e.Graph.Font = New Font("Tahoma", 14, FontStyle.Bold)
e.Graph.DrawString(reportHeader, Color.Black, rec, BorderSide.None)
New BrickStringFormat(StringAlignment.Center)New Font("Tahoma", 14, FontStyle.Bold) Dim rec As RectangleF = New RectangleF(0, 0, e.Graph.ClientPageSize.Width, 50)
End
Sub