August 19, 2010

Set Custom Paper Size as Crystal Report's Paper Size

Yesterday urgently I wanted to write a code to set a crystal reports page size into a custom page size. I checked every where but there were very little code to be found. Finally I managed to do it from the following code.

System.Drawing.Printing.PrintDocument doctoprint = new System.Drawing.Printing.PrintDocument();
doctoprint.PrinterSettings.PrinterName = "Microsoft XPS Document Writer";

for (int i = 0; i < papername ="="" the="" custom="" page="" name="">)
{
rawKind =
Convert.ToInt32(
doctoprint.PrinterSettings.PaperSizes[i].GetType().GetField("kind",
System.Reflection.
BindingFlags.NonPublic |
System.Reflection.
BindingFlags.Instance).
GetValue(doctoprint.PrinterSettings.PaperSizes[i]));
//crPrintOut.PrintOptions.PaperSize = rawKind;
_report.PrintOptions.PaperSize = (CrystalDecisions.Shared.PaperSize) rawKind;

break;
}
}

4 comments: