I want to Set Custome PaperSize of Printer into CrystalReportViewer>Print Report>Preferences>Advance>Paper Size.
Loading
I want to Set Custome PaperSize of Printer into CrystalReportViewer>Print Report>Preferences>Advance>Paper Size.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Jayraj ChhayaRank #304 · 8.2K reputationPosted Dec 12, 2024, 4:55 AM EST
Hi Gross Account,
To set a custom paper size for a printer in CrystalReportViewer, you can utilize the
PrinterSettingsclass in C#. Below is a step-by-step approach to achieve this:Create a Custom Paper Size: First, define your custom paper size using the
PaperSizeclass.Assign the Custom Paper Size to the PrinterSettings: Use the
PrinterSettingsobject to set the custom paper size.Set the PrinterSettings in the ReportDocument: Finally, apply the settings to your Crystal Report.
using System.Drawing.Printing; using CrystalDecisions.CrystalReports.Engine; using CrystalDecisions.Shared; // Create a new instance of the report ReportDocument reportDocument = new ReportDocument(); reportDocument.Load("YourReportPath.rpt"); // Define a custom paper size PaperSize customPaperSize = new PaperSize("CustomSize", 850, 1100); // Width and Height in hundredths of millimeters // Create PrinterSettings and assign the custom paper size PrinterSettings printerSettings = new PrinterSettings(); printerSettings.DefaultPageSettings.PaperSize = customPaperSize; // Set the PrinterSettings to the report reportDocument.PrintOptions.PrinterName = printerSettings.PrinterName; reportDocument.PrintOptions.PaperSize = (CrystalDecisions.Shared.PaperSize)customPaperSize; // Print the report reportDocument.PrintToPrinter(printerSettings, new PageSettings(), false);This code snippet will set the custom paper size for the printer when printing from the CrystalReportViewer. Ensure that the printer supports the specified paper size to avoid any printing issues.
Gross Account147 reputationPosted Dec 12, 2024, 8:21 AM EST
Thank For Answering
But Your Given Solution Not Working Properly.
reportDocument.PrintOptions.PaperSize = (CrystalDecisions.Shared.PaperSize)customPaperSize;
This one give error like "Cannot Convert type'System.Drawing.Printing.PaperSize''to "CrystalDecisions.Shared.PaperSize""
=>The error you are encountering occurs because
CrystalDecisions.Shared.PaperSize.PaperCustomis not a valid predefined value inCrystalDecisions.Shared.PaperSize. Unfortunately,CrystalDecisions.Shared.PaperSizedoes not have direct support for custom paper sizes.Jignesh KumarRank #91 · 22.9K reputationPosted Dec 15, 2024, 5:02 AM EST
Hello,
You can use below code to achive custom size,
using CrystalDecisions.CrystalReports.Engine; using CrystalDecisions.Shared; using System.Drawing.Printing; public void SetCustomPaperSizeToCrystalReportViewer(CrystalReportViewer crystalReportViewer, ReportDocument reportDocument) { PaperSize customPaperSize = new PaperSize("CustomSize", 850, 1100); PrinterSettings printerSettings = new PrinterSettings(); printerSettings.DefaultPageSettings.PaperSize = customPaperSize; reportDocument.PrintOptions.PrinterName = printerSettings.PrinterName; reportDocument.PrintOptions.PaperSize = PaperSizeEnum.PaperLetter; reportDocument.PrintOptions.Orientation = CrystalDecisions.Shared.Orientation.Landscape; crystalReportViewer.ReportSource = reportDocument; }