Saturday, 5 October 2013

Print the report using the custom print controller in vb.net

Print the report using the custom print controller in vb.net


Public Function GetPapersizeID(ByValPrinterNameAsString,ByValPaperSizeNameAsString)AsInteger
Dim doctoprint As New System.Drawing.Printing.PrintDocument()
Dim PaperSizeID As Integer=0
Dim ppname As String=""
Dim s As String=""
doctoprint.PrinterSettings.PrinterName=PrinterName'(ex."EpsonSQ-1170ESC/P2")
For i As Integer=0 To doctoprint.PrinterSettings.PaperSizes.Count-1
Dim raw Kind As Integer
ppname=PaperSizeName
If doctoprint.PrinterSettings.PaperSizes(i).PaperName=ppnameThen
rawKind=CInt(doctoprint.PrinterSettings.PaperSizes(i).GetType().GetField("kind",
Reflection.BindingFlags.InstanceOrReflection.BindingFlags.NonPublic).GetValue(doctoprint.PrinterSettings.PaperSizes(i)))
PaperSizeID=rawKind
ExitFor
EndIf
Next
Return PaperSizeID
End Function

Dim repOptions As CrystalDecisions.CrystalReports.Engine.PrintOptions
With ReportDocument
repOptions=.PrintOptions
.Load(ReportPath,CrystalDecisions.Shared.OpenReportMethod.OpenReportByDefault)
.SetDataSource(ds.Tables(0))
With rep Options
.PaperOrientation= CrystalDecision.Shared.PaperOrientation.Portrait
.PaperSize= GetPapersizeID("EPSON LX-300+II", "CEPCRP")
.PrinterName= "EPSON LX-300+II"
End With
.Refresh()
.PrintToPrinter(NumberOFCopies,Collated,StartPage,EndPage)
End With

No comments:

Post a Comment