set the Custome PaperSize of the Printer into CrystalReportViewer?

Conduct Exam

New member
Joined
Feb 29, 2024
Messages
4
Programming Experience
Beginner
I tried this solution But it can't be set to "9x6".

9x6" 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 ="9x6" the in PaperSize DropDown.
C#:
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;
}
 
Last edited by a moderator:
Are you getting an error or exception?

What guarantees do you have that you can safely cast the system PaperSize.RawKind to a CrystalDecisions.Shared.PaperSize?
 
This may or may not help:
 
I have created a custom page size (9x6). And I have set all the printer settings in the Windows Control Panel.
I have set the default custom paper size (9x6) in the Printing Preferences and Printer Properties.The problem is that when I hit the print button from Crystal Report Viewer, the printer's default paper size is reset from "9x6" to "Letter". Which does not change when printing from any other application like MS Work or Excel. The default paper size I have set is "9x6". So I want a solution. So that the print button of Crystal Report Viewer also comes with the default paper size set as "9x6". Like the print button of any other application like MS Work or Excel.

C#:
       private void cmbbilltype_SelectionChangeCommitted(object sender, EventArgs e)
        {
            try
            {
                LoadReport();
            }
            catch (Exception ex)
            {
                     LogFile.WriteToErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name + GeneralConstants.COLON + MethodBase.GetCurrentMethod().Name + GeneralConstants.COLON + ex.Message);
            }
        }       
        private void LoadReport()
        {
            PrintingDataSet database = new PrintingDataSet();
            database.ReadXmlSchema(DatabaseReport);
            ReportDocument rd = new ReportDocument();
            rd.Load(Application.StartupPath + "\\WithdrawalAdvice.rpt");
            rd.Database.Tables["depositadvice"].SetDataSource(dt);
            crvAdvicePrint.ReportSource = rd;
        }
 
Back
Top Bottom