4 Replies Latest reply on May 21, 2008 7:59 PM by Brent Wientjes

    Flex Printing


      For printing purposes I have created separate (from viewable application) container containing various components in the way I want them get printed. When users presses the print control on my flex application I populate this printable container and send it for printing using FlexPrintJob.

      Interestingly, if I set dataproviders in my printable container from various dataproviders already used by (view) application the print goes fine. But if I fetch data using http for any component (in this case a pieChart) then that component is not getting printed.

      For example in the below code does not work . But if I comment the line
      thePrintDetailView.dataPoint = "xyzData"; & uncomment the line below it - it works.

      if (printJob.start())

      var thePrintDetailView:PrintDetailView = new PrintDetailView();
      thePrintDetailView.dataPoint = "xyzData";
      //thePrintDetailView.perfPie.dataProvider = regionBreakdown.pcRegion.dataProvider;

      With above code as is by commenting the removeChild(thePrintDetailView); I have seen that new container gets rendered on Ui correctly but piechart does not appear on print altough it appears on UI.

      Also, see below the code of dataPoint for your reference

      public function set dataPoint(m:String):void
      srv1.url = m+".xml";
      perfData = new ArrayCollection();
      private function resultHandler1(event:ResultEvent):void
      perfData.source = event.result.list.category.source as Array;

      Girish Khemani
      Fidelity, India
        • 1. Re: Flex Printing
          Girish_Khemani Level 1
          Anybody Please
          • 2. Re: Flex Printing
            Garyl Woolworth Level 1
            This probably isn't the full answer to your problem. However I do know that FlexPrintJob isn't going to wait for your HTTP calls to get a result before it tries to print them. So if you tell it to print the view while it still has a call waiting or is still parsing the result it's going to take it as is whether it's finished or not. My suggestion would be to keep checking for the printJob.start() as your are now and when that matches true, call all of your HTTP services. Then on your final result when it's done parsing, THEN add the view to the printJob (printJob.addObject(thePrintDetailView);) and then finally remove your view and call your send method. I think once this is implemented it will help you in trouble shooting why certain components are / aren't showing up as well as maybe even fixing the issue.

            Just my thoughts.
            • 3. Re: Flex Printing
              Mitek17 Level 1
              Hi Girish,

              You have to wait until all your objects are loaded and rendered.
              From my experience creationComplete event is enough for DataGrids and simple objects. But for Images (and probably for charts as well) you have to wait for creationComplete & updatComplete events, as it after creation they are going to be resized.

              • 4. Re: Flex Printing
                Brent Wientjes
                I am trying to do something similar and had the exact same problem. I am trying to have a company logo dynamically added to a print job. All attempts at changing the source field on the image tag before printing failed. I tried creating an image object and adding to my print view before printing also failed. The image was generated and displayed on the screen after the print job left the computer. After trying a few ideas, I came up with this one that works but is ugly.

                The print job will take a completed object on the screen and add to the print view and then print correctly. So the solution was to create a "hidden" image of the logo when opening the report generator. I placed an image tag ahead of the data grid with both overlappnig on the screen. This makes the image hidden since the data grid comes later in the code. You then start the print job and add the hidden complete image to the print view. this prints correctly. Unfortunately, I found that the addObject function eats the mxml generated image so no second print attempt! To fix that, it turns out that if you generate dyanamically a second copy of the image tag upon opening the report generator, the addObject eats the static version and leaves the dynamically version alone. You can then print with the logo image with no problems repeatedly.

                As mentioned, this seems very ugly but I have now printed hundreds of different combinations and it seems to keep working.

                If anyone knows of a better solution, I would be very interested.