I want to set the Custome PaperSize of the Printer into CrystalReportViewer>Print Report>Preferences>Advance>Paper Size in C#.
I tried this solution But it can’t be set to “9×6”.
9×6″ I created this in the print server properties of the Printer.
But it can’t be set into CrystalReportViewer>Print Report>Preferences>Advance>Paper Size
I want to Set PaperSize =”9×6″ the in PaperSize DropDown.
private void LoadReport()
{
string customPaperSizeName = "9x6";
int customPaperSizeID = GetCustomPaperSizeID(customPaperSizeName);
ReportDocument report = new ReportDocument();
report.Load("WithdrawalAdvice.rpt");
report.PrintOptions.PaperSize = (CrystalDecisions.Shared.PaperSize)customPaperSizeID;
crystalReportViewer.ReportSource = report;
}
static int GetCustomPaperSizeID(string paperSizeName)
{
PrintDocument printDoc = new PrintDocument();
// Loop through available paper sizes for the default printer
foreach (PaperSize size in printDoc.PrinterSettings.PaperSizes)
{
if (size.PaperName.Equals(paperSizeName, StringComparison.OrdinalIgnoreCase))
{
return size.RawKind; // Return the PaperSize ID (RawKind)
}
}
// Return -1 if the custom paper size is not found
return -1;
}