I am trying to give my clients the option to preview a Crystal report using
the Crystal ReportViewer control on a web page, or sending the report
directly to their default printer, so far without success. The code I am
using follows:
Public oReport As CrystalDecisions.CrystalReports.Engine.ReportDocum ent
'PrintDirect is boolean parameter read from page header
Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load
Dim dsDataTable As New DataSet
' Code to fill the dataset
oReport.Load("myReport.rpt")
oReport.SetDataSource(dsDataTable)
If PrintDirect=True then
PrintReport(oReport)
else
CRViewer1.ReportSource = oReport
CRViewer1.DataBind()
end if
End Sub
Sub PrintReport(ByVal oReport as
CrystalDecisions.CrystalReports.Engine.ReportDocum ent)
Dim margins As PageMargins
With margins
.bottomMargin = 350
.leftMargin = 350
.rightMargin = 350
.topMargin = 350
End With
'Apply the page margins.
With oReport.PrintOptions
.PrinterName = "" 'default printer
.ApplyPageMargins(margins)
End With
'Print the report. Set the startPageN and endPageN
'parameters to 0 to print all pages.
oReport.PrintToPrinter(1, False, 0, 0)
End Sub
The report correctly displays on the Crystal ReportsViewer, but will not
output to the printer, even if I include a specific printer name. Any help
would be appreciated.