Symptom
- The Crystal Reports SDK for .NET is not as functional and featured as the RAS SDK for .NET
- The Crystal Reports SDK for .NET may result in printing issues such as;
- Difficulty setting new printer
- Setting page orientation
- Setting page margins
- Setting paper tray
- and more
Environment
- Any full or "stand-alone" version of Crystal Reports
- Crystal Reports for Visual Studio 2010
Resolution
- Use the RAS SDK for .NET
- The RAS SDK is more functional as well as better maintained
- Use the RAS PrintOutputController as described in the code below
- The code uses the Common Dialog Printer box
- Hard coding the values is also possible
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using CrystalDecisions.ReportAppServer.ClientDoc;
using CrystalDecisions.ReportAppServer.Controllers;
using CrystalDecisions.ReportAppServer.ReportDefModel;
using CrystalDecisions.ReportAppServer.CommonControls;
using CrystalDecisions.ReportAppServer.CommLayer;
using CrystalDecisions.ReportAppServer.CommonObjectModel;
using CrystalDecisions.ReportAppServer.ObjectFactory;
using CrystalDecisions.ReportAppServer.DataSetConversion;
using CrystalDecisions.ReportAppServer.DataDefModel;
public class frmMain : System.Windows.Forms.Form
{
CrystalDecisions.CrystalReports.Engine.ReportDocument rpt = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument rptClientDoc;
...
private void btnSetPrinter_Click(object sender, System.EventArgs e)
{
System.Drawing.Printing.PrintDocument pDoc = new System.Drawing.Printing.PrintDocument();
CrystalDecisions.ReportAppServer.Controllers.PrintReportOptions rasPROpts = new CrystalDecisions.ReportAppServer.Controllers.PrintReportOptions();
CrystalDecisions.ReportAppServer.ReportDefModel.PrintOptions MYPRTOpts = new CrystalDecisions.ReportAppServer.ReportDefModel.PrintOptions();
if (rdoCurrent.Checked)
{
pDoc.PrinterSettings.PrinterName = cboCurrentPrinters.Text;
MYPRTOpts.PrinterName = cboCurrentPrinters.Text;
MYPRTOpts.PaperSize = (CrPaperSizeEnum)
pDoc.PrinterSettings.PaperSizes[cboCurrentPaperSizes.SelectedIndex].Kind;
MYPRTOpts.PaperSource = (CrPaperSourceEnum)
pDoc.PrinterSettings.PaperSources[cboCurrentPaperTrays.SelectedIndex].Kind;
// added the below line to verify the changes work.
MYPRTOpts.PaperOrientation = CrPaperOrientationEnum.crPaperOrientationLandscape;
}
else
{
pDoc.PrinterSettings.PrinterName = cboDefaultPrinters.Text;
MYPRTOpts.PrinterName = cboDefaultPrinters.Text;
MYPRTOpts.PaperSize = (CrPaperSizeEnum)
pDoc.PrinterSettings.PaperSizes[cboDefaultPaperSizes.SelectedIndex].Kind;
MYPRTOpts.PaperSource = (CrPaperSourceEnum)
pDoc.PrinterSettings.PaperSources[cboDefaultPaperTrays.SelectedIndex].Kind;
}
rptClientDoc.PrintOutputController.ModifyPrintOptions(MYPRTOpts);
MessageBox.Show("Printer set.", "RAS", MessageBoxButtons.OK,MessageBoxIcon.Information );
rptClientDoc.PrintOutputController.PrintReport(rasPROpts);
MessageBox.Show("Printing report.", "RAS", MessageBoxButtons.OK,MessageBoxIcon.Information );
}
Keywords
In Proc Process CR2010 2010 CR4VS2010 CR4VS VS2010 NET2010 printer print , KBA , BI-DEV-NET-SDK , .NET SDK / COM SDK , How To
Product
Crystal Reports 2008 V1 ; SAP Crystal Reports 10.0 ; SAP Crystal Reports 2011 ; SAP Crystal Reports XI ; SAP Crystal Reports XI R2