16 Replies Latest reply on May 7, 2010 6:14 AM by phantoxe

    AdvancedDataGrid Print Issue

    Rajeesh Upendran Level 1

      Hi

       

      I am using the AdvanceDataGrid to display the record. When try to use the FlexPrintJob object to print the AdvanceDataGrid, It is just the printing the first page and rest of page are getting ignored. Also some time the below error is showing

       


      Error:Error #1502: A script has executed for longer than the default timeout period of 15 seconds.
      at flash.printing::PrintJob/get pageWidth()
      at mx.printing::FlexPrintJob/start()
      at index/btnPrint_click_handler()

       

       

      Code is given below

       

      public function btnPrint_click_handler ( e:MouseEvent ) : void
          {
              // Create an instance of the FlexPrintJob class.
              var printJob:FlexPrintJob = new FlexPrintJob();
             
              // Initialize the PrintAdvancedDataGrid control.
              var printADG:PrintAdvancedDataGrid =
                  new PrintAdvancedDataGrid();
              // Exclude the PrintAdvancedDataGrid control from layout.
              printADG.includeInLayout = false;
              adg1.validateNow();
              adg1.expandAll();     
              printADG.source = adg1;
           
              // Add the print-specific control to the application.               
              addChild(printADG);
             
              // Start the print job.
              if (printJob.start() == false) {               
                  // User cancelled print job.
                  // Remove the print-specific control to free memory.               
                  removeChild(printADG);
                  return;
              }

       

              // Add the object to print. Do not scale it.
              printJob.addObject(printADG, FlexPrintJobScaleType.NONE);

       

              // Send the job to the printer.
              printJob.send();

       

              // Remove the print-specific control to free memory.               
              removeChild(printADG);
          }

       

      Can you please guide me

       

      regards,
      Rajeesh

        • 1. Re: AdvancedDataGrid Print Issue
          Sameer Bhatt Adobe Employee

          You have to call nextPage() and add each page to printing -

           

                          while (printADG.validNextPage)
                          {
                              printADG.nextPage();
                              printJob.addObject(printADG, FlexPrintJobScaleType.NONE);
                          }
          
          • 2. Re: AdvancedDataGrid Print Issue
            Ansury Level 3

            http://www.adobe.com/devnet/flex/tourdeflex/langref/mx/printing/PrintAdvancedDataGrid.html #includeExamplesSummary

             

            Edit: That's curious, the link above doesn't call nextPage() like I believe the PrintDataGrid example does.  No time to look at that now but hopefully this still works/helps.  Maybe you need to look at this too for a fancier example:

             

            http://www.adobe.com/livedocs/flex/3/langref/mx/printing/PrintDataGrid.html#includeExample sSummary

             

             

            Printing in Flex can be a challenge and I'm very disappointed that Flex 4 (not to mention Flash 10) didn't improve on this capability.

            • 3. Re: AdvancedDataGrid Print Issue
              Rajeesh Upendran Level 1

              Hi Sameer Bhatt,

               

               

              Thanks for your support.

               

              I have tried this code but printADG.validNextPage value always false. In AdvancedDataGrid data is showing but I could not able to print the all values.

               

              Thanks

              Rajeesh

              • 4. Re: AdvancedDataGrid Print Issue
                Rajeesh Upendran Level 1

                Hi Ansury

                 

                Thanks for your support.

                 

                I have used the same code but no luck

                 

                Thanks

                Rajeesh

                • 5. Re: AdvancedDataGrid Print Issue
                  Sameer Bhatt Adobe Employee

                  Can you post a sample?

                  • 6. Re: AdvancedDataGrid Print Issue
                    Rajeesh Upendran Level 1

                    Hi Sameer,

                     

                    Code is given below

                     

                     

                    public function btnPrint_click_handler ( e:MouseEvent ) : void
                        {
                            // Create an instance of the FlexPrintJob class.
                            var printJob:FlexPrintJob = new FlexPrintJob();
                           
                            // Initialize the PrintAdvancedDataGrid control.
                            var printADG:PrintAdvancedDataGrid =
                                new PrintAdvancedDataGrid();
                            // Exclude the PrintAdvancedDataGrid control from layout.
                            printADG.includeInLayout = false;
                            adg1.validateNow();
                            adg1.expandAll();
                            printADG.source = adg1;
                            printADG.validateNow();
                            //Alert.show(printADG.validNextPage);
                            while (printADG.validNextPage)
                            {
                                printADG.nextPage();
                                printJob.addObject(printADG, FlexPrintJobScaleType.NONE);
                            }

                     

                         }

                     

                    Thanks

                    Rajeesh

                    • 7. Re: AdvancedDataGrid Print Issue
                      Sameer Bhatt Adobe Employee

                      You have to add the PrintAdvancedDataGrid control (as a child) to the Application and then later remove it.

                      • 8. Re: AdvancedDataGrid Print Issue
                        Rajeesh Upendran Level 1

                        I have tried this but no luck . I getting this error

                         

                        Error: Error #1502: A script has executed for longer than the default timeout period of 15 seconds.
                            at mx.printing::FlexPrintJob/addObject()[C:\autobuild\3.2.0\frameworks\projects\framework\sr c\mx\printing\FlexPrintJob.as:358]
                            at index/btnPrint_click_handler()[X:\wwwroot\IBMFLEX3\SalesCancelReport\src\com\controller.a s:334]

                         

                        Code is given below

                         

                        public function btnPrint_click_handler ( e:MouseEvent ) : void
                            {
                                // Create an instance of the FlexPrintJob class.
                                var printJob:FlexPrintJob = new FlexPrintJob();
                               
                                // Initialize the PrintAdvancedDataGrid control.
                                var printADG:PrintAdvancedDataGrid =
                                    new PrintAdvancedDataGrid();
                                // Exclude the PrintAdvancedDataGrid control from layout.
                                printADG.includeInLayout = false;
                                adg1.validateNow();
                                adg1.expandAll();
                                printADG.source = adg1;
                                printADG.validateNow();
                               
                                while (printADG.validNextPage)
                                {
                                    printADG.nextPage();
                                    printJob.addObject(printADG, FlexPrintJobScaleType.NONE);
                                }
                              
                                // Add the print-specific control to the application.               
                                addChild(printADG);
                               
                                // Start the print job.
                                if (printJob.start() == false) {               
                                    // User cancelled print job.
                                    // Remove the print-specific control to free memory.               
                                    removeChild(printADG);
                                    return;
                                }

                         

                                // Add the object to print. Do not scale it.
                                printJob.addObject(printADG, FlexPrintJobScaleType.NONE);

                         

                                // Send the job to the printer.
                                printJob.send();

                         

                                // Remove the print-specific control to free memory.               
                                removeChild(printADG);
                            }

                        • 9. Re: AdvancedDataGrid Print Issue
                          Sameer Bhatt Adobe Employee

                          Call addChild(printADG); just after creating the printADG, that is, do -

                          var printADG:PrintAdvancedDataGrid =

                                      new PrintAdvancedDataGrid();

                          addChild(printADG);

                           

                          .... rest of the code .....

                          • 10. Re: AdvancedDataGrid Print Issue
                            Rajeesh Upendran Level 1

                            Thanks for your support

                            I tried the below code but no progress

                             

                            public function btnPrint_click_handler ( e:MouseEvent ) : void
                            {

                             

                            var printJob:FlexPrintJob = new FlexPrintJob();


                            var printADG:PrintAdvancedDataGrid =
                            new PrintAdvancedDataGrid();

                             

                            addChild(printADG);

                             

                            printADG.includeInLayout = false;
                            adg1.validateNow();
                            adg1.expandAll();
                            printADG.source = adg1;


                            if (printJob.start() == false)
                            {
                            removeChild(printADG);
                            return;
                            }

                             

                            printJob.addObject(printADG, FlexPrintJobScaleType.NONE);

                             

                            printJob.send();

                             

                            removeChild(printADG);
                            }

                             

                            Thanks

                            Rajeesh

                            • 11. Re: AdvancedDataGrid Print Issue
                              Sameer Bhatt Adobe Employee

                              Here is a working sample -

                               

                              <?xml version="1.0" encoding="utf-8"?>
                              <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
                                                xmlns:s="library://ns.adobe.com/flex/spark" 
                                                xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
                                   <s:layout>
                                        <s:VerticalLayout/>
                                   </s:layout>
                              
                                   <fx:Script>
                                        <![CDATA[
                                             import mx.printing.FlexPrintJob;
                                             import mx.printing.FlexPrintJobScaleType;
                                             import mx.printing.PrintAdvancedDataGrid;
                                             protected function button1_clickHandler(event:MouseEvent):void
                                             {
                                                  var printJob:FlexPrintJob = new FlexPrintJob();
                                                  
                                                  padg.visible = true;
                                                  padg.includeInLayout = true;
                                                  
                                                  adg.expandAll();
                                                  adg.validateNow();
                                                  
                                                  padg.source = adg;
                                                  padg.validateNow();
                                                  
                                                  if (printJob.start())
                                                  {
                                                       printJob.addObject(padg, FlexPrintJobScaleType.NONE);
                                                       while(padg.validNextPage)
                                                       {
                                                            padg.nextPage();
                                                            printJob.addObject(padg, FlexPrintJobScaleType.NONE);
                                                       }
                                                       
                                                       printJob.send();
                                                  }
                                                  
                                                  padg.visible = false;
                                                  padg.includeInLayout = false;
                                             }
                                        ]]>
                                   </fx:Script>
                              
                                   <fx:Declarations>
                                        <!-- Place non-visual elements (e.g., services, value objects) here -->
                                        <fx:Array id="arr">
                                             <fx:Object name="A" sno="1" age="10" />
                                             <fx:Object name="A1" sno="2" age="20" />
                                             <fx:Object name="A2" sno="3" age="30" />
                                             <fx:Object name="A3" sno="4" age="40" />
                                             <fx:Object name="A4" sno="5" age="50" />
                                             <fx:Object name="A5" sno="6" age="60" />
                                             <fx:Object name="A6" sno="7" age="70" />
                                             <fx:Object name="A7" sno="8" age="60" />
                                             <fx:Object name="A8" sno="9" age="50" />
                                             <fx:Object name="A9" sno="10" age="40" />
                                             <fx:Object name="A10" sno="11" age="30" />
                                             <fx:Object name="A11" sno="12" age="20" />
                                             <fx:Object name="A12" sno="13" age="10" />
                                             <fx:Object name="A13" sno="14" age="30" />
                                             <fx:Object name="A14" sno="15" age="40" />
                                             <fx:Object name="A15" sno="16" age="30" />
                                             <fx:Object name="A16" sno="17" age="20" />
                                             <fx:Object name="A17" sno="18" age="10" />
                                             <fx:Object name="A18" sno="19" age="30" />
                                             <fx:Object name="A19" sno="20" age="40" />
                                        </fx:Array>
                                   </fx:Declarations>
                                   <mx:PrintAdvancedDataGrid id="padg" includeInLayout="false" visible="false" width="400" height="400" />
                                   <mx:AdvancedDataGrid id="adg" creationComplete="gc.refresh();">
                                        <mx:dataProvider>
                                             <mx:GroupingCollection2 id="gc" source="{arr}">
                                                  <mx:Grouping label="name">
                                                       <mx:GroupingField name="name" />
                                                  </mx:Grouping>
                                             </mx:GroupingCollection2>
                                        </mx:dataProvider>
                                        <mx:columns>
                                             <mx:AdvancedDataGridColumn dataField="name" />
                                             <mx:AdvancedDataGridColumn dataField="sno" />
                                             <mx:AdvancedDataGridColumn dataField="age" />
                                        </mx:columns>
                                   </mx:AdvancedDataGrid>
                                   <s:Button label="Print" click="button1_clickHandler(event)" />
                              </s:Application>
                              
                              
                              • 12. Re: AdvancedDataGrid Print Issue
                                phantoxe Level 1

                                Is this a Flash Builder 4 example?

                                • 13. Re: AdvancedDataGrid Print Issue
                                  Sameer Bhatt Adobe Employee

                                  Yes this sample is built with Flex 4 SDK. You can use the same printing code in Flex 3 SDK also.

                                  • 14. Re: AdvancedDataGrid Print Issue
                                    phantoxe Level 1

                                    Hi Guys... somebody help me? I need put a company logo before my PRINT. And I need put other Logo in the END my Page... I TRIED this but dosent work:

                                     

                                    var companyLogo:Image = new Image():

                                    companyLogo.source = "assets/logo.png";

                                     

                                    var miniCompanyLogo:Image = new Image():

                                    miniCompanyLogo.source = "assets/logo_mino.png";

                                     

                                    printJob.addObject(companyLogo, FlexPrintJobScaleType.NONE); // This is my First Logo

                                    printJob.addObject(padg, FlexPrintJobScaleType.NONE); // This is my PrintAdvancedDatagrid

                                     

                                    printJob.addObject(miniCompanyLogo, FlexPrintJobScaleType.NONE); // This is my Last Logo

                                     

                                     

                                    Thanks

                                     

                                    Eduardo

                                     

                                     

                                     

                                     

                                     

                                     

                                     

                                    • 15. Re: AdvancedDataGrid Print Issue
                                      Sameer Bhatt Adobe Employee

                                      You are not adding the Images (as a child) to the  Application.

                                      • 16. Re: AdvancedDataGrid Print Issue
                                        phantoxe Level 1

                                        Hi Sameer... thanks pro reply...

                                         

                                        I tried this man e dosen't work:

                                         

                                                            var printJob:FlexPrintJob = new FlexPrintJob();
                                                            var logoPrint:Image = new Image();
                                                            logoPrint.source = "assets/iobras.png";
                                                            addChild(logoPrint);
                                                           
                                                            padg.visible = true;
                                                            padg.includeInLayout = true;
                                                           
                                                            listRelDespesas_dg.expandAll();
                                                            listRelDespesas_dg.validateNow();
                                                           
                                                            padg.source = listRelDespesas_dg;
                                                            padg.validateNow();
                                                           
                                                            if (printJob.start())
                                                            {
                                                                 printJob.addObject(logoPrint, FlexPrintJobScaleType.NONE);
                                                                 printJob.addObject(padg, FlexPrintJobScaleType.NONE);
                                                                 while(padg.validNextPage)
                                                                 {
                                                                      padg.nextPage();
                                                                      printJob.addObject(padg, FlexPrintJobScaleType.NONE);
                                                                 }
                                                                
                                                                 printJob.send();
                                                            }
                                                           
                                                            padg.visible = false;
                                                            padg.includeInLayout = false;