2 Replies Latest reply on Jun 23, 2010 9:01 PM by paulcortez

    PrintDataGrid printing only half the page

    paulcortez

      Hello,

       

      I have a problem printing my report with PrintDataGrid. I just copied and paste the sample code form this site but it seems to have a problem. The print out in the paper is only half and jumps to another page. 1 to 6 row is on the first page and the rest is on the next page which supposed to be on a single page. I'm asking for your help finding ways to make it print correctly.

       

      here i have the code:

       

      FormSalesTransaction.mxml

       

      <fx:Script>
                <![CDATA[
                     import mx.core.*
                          
                          // Declare and initialize the variables used in the component.
                          // The application sets the actual prodTotal value.
                     [Bindable]
                     public var pageNumber:Number = 1;
                     [Bindable]
                     public var prodTotal:Number = 0;
                     
                     // Control the page contents by selectively hiding the header and
                     // footer based on the page type.
                     public function showPage(pageType:String):void 
                     {
                          if(pageType == "first" || pageType == "middle") 
                          {
                               // Hide the footer.
                               footer.includeInLayout=false;
                               footer.visible = false;
                          }
                          if(pageType == "middle" || pageType == "last") 
                          {
                               // The header won't be used again; hide it.
                               header.includeInLayout=false;
                               header.visible = false;
                          }
                          if(pageType == "last") 
                          {
                               // Show the footer.
                               footer.includeInLayout=true;
                               footer.visible = true;
                          }
                          //Update the DataGrid layout to reflect the results.
                          validateNow();
                     }
                ]]>
           </fx:Script>
           
           <!-- The template for the printed page, 
           with the contents for all pages. -->
           <mx:VBox width="90%" horizontalAlign="left">
                <mx:Label text="Page {pageNumber}"/>
           </mx:VBox>
           <MyComp:FormPrintHeader id="header"/>
           
           <mx:PrintDataGrid id="myDataGrid" 
                                 height="100%"
                                 width="100%"
                                 fontSize="7" 
                                 wordWrap="true" 
                                 variableRowHeight="true" 
                                 fontFamily="Lucida Console" >
                <!-- Specify the columns to ensure that their order is correct. -->
                <mx:columns>
                     <mx:DataGridColumn headerText="Invoice" dataField="InvoiceNo" width="65"/>
                     <mx:DataGridColumn headerText="Customer" dataField="CustomerName" width="100"/>
                     <mx:DataGridColumn headerText="Model" dataField="ModelNo" width="70"/>
                     <mx:DataGridColumn headerText="Category" dataField="CategoryCode" width="70"/>          
                     <mx:DataGridColumn headerText="Price" dataField="Price" width="80"/>
                     <mx:DataGridColumn headerText="Qty" dataField="Quantity" width="35"/>                    
                     <mx:DataGridColumn headerText="Cash" dataField="Cash" width="80"/>
                     <mx:DataGridColumn headerText="Dollar" dataField="Dollar" width="80"/>
                     <mx:DataGridColumn headerText="Cr Card" dataField="CreditCard" width="80"/>
                     <mx:DataGridColumn headerText="B Share" dataField="Bankshare" width="80"/>
                     <mx:DataGridColumn headerText="W Tax" dataField="WTax" width="80"/>
                     <mx:DataGridColumn headerText="Lay Dep" dataField="LayawayDP" width="80"/>
                     <mx:DataGridColumn headerText="Lay Bal" dataField="LayawayBal" width="80"/>
                     <mx:DataGridColumn headerText="Check" dataField="Check" width="80"/>
                     <mx:DataGridColumn headerText="Misc" dataField="Misc" width="80"/>
                     <mx:DataGridColumn headerText="Remarks" dataField="Remarks"/>
                     <mx:DataGridColumn headerText="Lay Pay" dataField="LayawayPayment" width="80"/>
                </mx:columns>
           </mx:PrintDataGrid>
      

       

       

       

      and the way i call it from Report.mxml:

       

       

      var printJob:FlexPrintJob = new FlexPrintJob();
                          
      if (printJob.start()) {
              var thePrintView:FormSalesTransaction = new FormSalesTransaction();
           addElement(thePrintView);
                               
           thePrintView.width=printJob.pageWidth;
           thePrintView.height=printJob.pageHeight;
                                                   
           thePrintView.prodTotal = prodTotal;
                               
           thePrintView.myDataGrid.dataProvider = salesTransaction;
                               
           thePrintView.validateNow();
                               
           if(!thePrintView.myDataGrid.validNextPage)
           {
                thePrintView.showPage("single");
                printJob.addObject(thePrintView, FlexPrintJobScaleType.MATCH_WIDTH);
           }
           else
           {
                thePrintView.showPage("first");
                printJob.addObject(thePrintView, FlexPrintJobScaleType.MATCH_WIDTH);
                thePrintView.pageNumber++;
                                    
                while(true)
                {
                     thePrintView.myDataGrid.nextPage();
                                         
                     thePrintView.showPage("last");  
                                         
                     if(!thePrintView.myDataGrid.validNextPage) 
                     {
                          printJob.addObject(thePrintView, FlexPrintJobScaleType.MATCH_WIDTH);
                          break;
                     }
                     else
                     {
                          thePrintView.showPage("middle");
                          printJob.addObject(thePrintView, FlexPrintJobScaleType.MATCH_WIDTH);
                          thePrintView.pageNumber++;
                     }
                }
           }
           removeElement(thePrintView);
      }          
      printJob.printAsBitmap = false;                    
      printJob.send();
      

       

       

      Here is the output when I print the report:

      printout.jpg

       

      I hope you could have some time to help me.

       

      Thankz a lot.