Symptom
Paper Tray setting is not used when sending to printer through Crystal Reports .NET SDK.
Environment
- Crystal Reports for Visual Studio 2012
- Crystal Reports for Visual Studio 2010
- Crystal Reports for Visual Studio 2008
- Crystal Reports for Visual Studio 2005
Resolution
For example, when I select “A4”, the cboCurrentPaperSizes .SelectedIndex is “5”. But in CrPaperSizeEnum, “5” means “crPaperSizePaperLegal”, A4 is 9. So the sdk set the wrong papaersize(Legal) here. I modify the code as follows.
Original code:
rasPROpts.PaperSize = (CrPaperSizeEnum)cboCurrentPaperSizes.SelectedIndex;
Modified code:
int[] sizes = PaperSizeGetter.Get_PaperSizes(cboCurrentPrinters.Text);
int paperSizeid = sizes[this.cboCurrentPaperSizes.SelectedIndex];
if (paperSizeid > 0)
{
rasPROpts.PaperSize = (CrystalDecisions.ReportAppServer.ReportDefModel.CrPaperSizeEnum)paperSizeid;
}
Let's return, the root cause of Paper Tray not work is as follow. Because selectedtext will return empty string “”, if DropDownStyle is set to DropDownList(You can find it in msdn). In this way the original SDK always returns empty string, so BinName is always empty. The situation you mention will appear, “For the HP 4050 it always selects Tray 1 first, when it runs out of paper then Tray 2 is used.”
Original code:
rasPROpts.BinName = cboDefaultPaperTrays.SelectedText;
Modified code:
rasPROpts.BinName = cboCurrentPaperTrays.SelectedItem.ToString();
The modification above is just for PrintOutputController.PrintReport. PrintToPrinter should modify as follows. We should assign a PaperSource to pSettings.PaperSource, not only the papersource name.
Original code:
pSettings.PaperSource.SourceName = cboCurrentPaperTrays.SelectedText;
Modified code:
System.Drawing.Printing.PaperSource myPaperSource = new System.Drawing.Printing.PaperSource();
pDoc.PrinterSettings.PrinterName = cboCurrentPrinters.SelectedItem.ToString();
foreach (System.Drawing.Printing.PaperSource tmpPaperSource in pDoc.PrinterSettings.PaperSources)
{
if (tmpPaperSource.SourceName == cboCurrentPaperTrays.SelectedItem.ToString())
{
myPaperSource = tmpPaperSource;
break;
}
}
pSettings.PaperSource = myPaperSource;
See attached C# file for more info on how to query the printers for the above info.
Keywords
KBA , BI-DEV-NET , BI Software Development Kits (SDKs) - .NET or Other , Problem
Product
Attachments
PaperSizeGetter.zip |