We have a series of reports for a new application. As part of the process
flow, these reports should be generated and printed at the conclusion of the
transaction. Prior to this requirement, each report, in turn, were
displayed in the CrystalViewer and manually printed by the user.
We stopped passing the reports through the viewer and simply executed the
PrintToPrinter() method. For the most part this is fine, except that on a
couple reports, the calculated fields on the far right of the document are
truncated. I had thought that I had inadvertantly fat fingered something,
and on a lark ran the report through the viewer again in an attempt to save
paper, thinking that I would see WYSIWYG results. The viewer was fine so I
printed the report. The report was fine.
Needless to say after much testing, it does appear that the Viewer properly
sends the report out to the printer, while sending report directly to the
printer does not have the desired results.
We then decided to use the viewer and simply call the PrintReport() method.
This is obviously wrong, since it throws exception. (Unable to send the
report to the printer:System.ArgumentException: '-1' is not a valid value
for 'value'. 'value' must be greater than or equal to 0.) There are a
series of reports that need to be printed, a printer should be selected only
once.
Code to get there:
'objReport is CrystalDecisions.CrystalReports.Engine.ReportDocum ent
'viewer is CrystalDecisions.Windows.Forms.CrystalReportViewer
'Printer is Drawing.Printing.PrinterSettings and PrinterName is set
Try
objReport.PrintOptions.PrinterName = Printer.PrinterName
'I would prefer to call this
'objReport.PrintToPrinter(Copies, True, 0, 0)
viewer.ReportSource = objReport
viewer.PrintReport()
Catch ex As Exception
'...
End Try
We must either figure out a way to use the PrintToPrinter() of the report
document or the PrintReport() of the viewer. OLE Automation of Office
products is not an option, nor are HTML, XML/CSS viable solutions. Crystal
has to be the end solution.
VS.Net 2003, integrated crystal reports for .Net
..Net Framework 1.1 sp1
Thanks in advance.