Friday, February 5, 2010

How to Print Crystal Report using PrintDocument control in VB.NET?

Try
Dim strReportPath As String = System.Windows.Forms.Application.StartupPath & "\CR.rpt"
If Not IO.File.Exists(strReportPath) Then
Throw (New Exception("Unable to locate report file:" & vbCrLf & strReportPath))
End If
rptDocument.Load(strReportPath)
CrystalReportViewer1.ReportSource = rptDocument
CrystalReportViewer1.Zoom(25)
Dim custompos As Integer
Dim customnumber As Integer
For custompos = 0 To PrintDocument1.PrinterSettings.PaperSizes.Count - 1
If PrintDocument1.PrinterSettings.PaperSizes.Item(custompos).PaperName = "US Std Fanfold" Then
customnumber = PrintDocument1.PrinterSettings.PaperSizes.Item(custompos).RawKind
Exit For
End If
Next
rptDocument.PrintOptions.PaperSize = customnumber
rptDocument.PrintToPrinter(1, True, 0, 0)
Catch ex As Exception
MsgBox(ex.Message)
End Try

1 comment:

  1. hi vennila,
    all the best for your blog.

    regards,
    rajeshkumar govindarajan

    ReplyDelete