1 Reply Latest reply on May 3, 2006 12:11 AM by martypulincunnoo

    Flex Printing Issue

    ship2moon
      Dear All,

      I have used the following code to print from flex Datagrid in Flex 1.5.

      public function doPrint():Void {
      var pj : PrintJob = new PrintJob();

      //Save the current vertical scroll position of the DataGrid control.
      var prev_vPosition:Number = dgReportFinal.vPosition;

      if(pj.start() != true) {
      delete pj;
      return;
      }

      //Calculate the number of visible rows.
      var rowsPerPage:Number = Math.floor((dgReportFinal.height - dgReportFinal.rowHeight)/dgReportFinal.rowHeight);

      //Calculate the number of pages required to print all rows.
      var pages:Number = Math.ceil(dgReportFinal.dataProvider.length / rowsPerPage);

      //Scroll down each page of rows, then call addPage() once for each page.
      for (var i=0;i<pages;i++) {
      dgReportFinal.vPosition = i*rowsPerPage;
      pj.addPage(dgReportFinal);
      }

      pj.send();
      delete pj;

      // Restore vertical scroll position.
      dgReportFinal.vPosition = prev_vPosition;
      }

      My Issues are:
      1. I want content of the DataGrid to be printed, but the printing prints the content of the datagrid along with the scrollbars.
      This is the same, when I use landscape mode also.

      2. When the content of the Datagrid exceeds the width of the Datagrid (i.e., when we have a hscroll), those contents are not printed. I think only the content which we view currently is being printed.

      To print headers and footers which are the best controls to use. Bcoz my headers would look like:
      /**************************************************************************************/
      Date: Organization:
      Place: Branch:
      Report Title
      /**************************************************************************************/

      Thanks in advance.

      thanks and regards,
      Loganathan.P.C.

        • 1. Re: Flex Printing Issue
          martypulincunnoo
          The feature of printing data which is not visible in the control is not available in Flex 1.5 but is available in Flex 2 (Beta). Work around can be fragmenting the data as pages for printing but involves splitting data in grid into a fixed number of rows for each page.

          I can also suggest a work around for you header and footer issue. you can create a sepearate Print Preview Page which can be invisible / visible as you wish and on click of print use the controls in that page and print

          tipically the Preview page can be like

          mx:Label ---> Header text

          mx ataGrid -- > data which is paged -

          mx:Label --- > footer