Friday, September 28, 2012

Programatically Set Custom PaperSize in CrystalReport

Programatically Set Custom 
PaperSize 
in CrystalReport

Hi,
     For one of our clients we are using crystal report  developed using Visual Studio 2005. At the deployment phase we often come across the problem of Setting Custom PaperSize in report. Our client is using custom page size of 11in x 6in , whenever the report preview is shown the report viewer automatically sets the size to A4. So the user can't able to view or print the report. So i searched  a lot to set paper size programatically. At last i found the following solution ,

  i)  First i have created Custom PageSize using ServerProperties (ie.,11in x 6in)  and named it as 11x6.

  ii) Then added the following method to my code,

  public Int32 GetPaperSize(String sPrinterName, String sPaperSizeName)
        {
            PrintDocument docPrintDoc = new PrintDocument();
            docPrintDoc.PrinterSettings.PrinterName = sPrinterName;
            for (int i = 0; i < docPrintDoc .PrinterSettings.PaperSizes.Count; i++)
            {
                int raw = docPrintDoc.PrinterSettings.PaperSizes[i].RawKind;           
                if (docPrintDoc.PrinterSettings.PaperSizes[i].PaperName == sPaperSizeName)
                {
                    return raw;
                }
            }
            return 0;
        }

  iii) Then i called this method  for the current Crystal Report Document, In my case 
CrystalReport11 is the Report Document



                this.CrystalReport11.PrintOptions.PrinterName = "Wipro LQ 1050+DX
";

                this.CrystalReport11.PrintOptions.PaperSize = (CrystalDecisions.Shared.PaperSize)GetPapersizeID("Wipro LQ 1050+DX
", "11x6";




                   

11 comments:

  1. Very nice to me. Thanks..........

    Crystal Custom

    ReplyDelete
  2. Awesome looking blog. I love this.

    Crystal Custom

    ReplyDelete
  3. This comment has been removed by a blog administrator.

    ReplyDelete
  4. If the database you are using supports a query language such as SQL, you can write your own command which will be represented in Crystal Reports as a Table object

    Crystal Custom

    ReplyDelete
  5. This comment has been removed by a blog administrator.

    ReplyDelete
  6. This comment has been removed by a blog administrator.

    ReplyDelete
  7. This comment has been removed by a blog administrator.

    ReplyDelete
  8. Hi Bala,

    The Custom paper size(8X6)is affected in crystal preview but while
    actually printing it will take letter size please give the solution

    ReplyDelete
    Replies
    1. Hi sunny,
      you have to add the paper size in server property of that particular machine in which you have configured your printer.

      Delete
    2. Hi Bala,
      I've done it already,But when i view the report in crystal report from Visual studio 2008 it shows properly but when i click on to print button & check preferences it shows the papersize as Letter & prints accordingly.

      Delete