4 Replies Latest reply on Feb 8, 2012 5:44 AM by Gudril

    Problem with printing after migrating from 3.5 to 4.1

    Gudril Level 1

      Hello everyone,

       

      I'm currently working on an application that was recently migrated (by someone else) from Flex 3.5 to Flex 4.1 and I discovered the printing doesn't work properly anymore. So I tried to find out what the problem was and after many tries, I came to the conclusion that the problem was within the following line:

       

      printJob.addObject(myPrintView,FlexPrintJobScaleType.MATCH_WIDTH);

       

      (Of course "myPrintView" is not the real name used in the app but that's not important)

      I searched on the Internet and this line is supposed to work in 4.1, isn't it? However, the printed version cuts my PrintAdvancedDataGrid approximately in half. I tried to change the width property from myPrintView but the grid is still cut at the same place, its cells are just distorted.

       

      FYI, you can find a part of the code right here:

       

      var printJob:FlexPrintJob = new FlexPrintJob();

                          if (printJob.start()) {

           //A lot of code to build the print view

        }

      myPrintView.width=1280;

      printJob.addObject(myPrintView,FlexPrintJobScaleType.MATCH_WIDTH);

      printJob.send();

      myPanel.removeChild(myPrintView);

       

      Any help would be appreciated.

       

      Regards,

       

      Gudril

        • 1. Re: Problem with printing after migrating from 3.5 to 4.1
          Gudril Level 1

          While looking for a solution on the Internet I found some people having troubles because of the structure of their AdvancedDataGrid. My problem doesn't come from any example I've seen but maybe it's still linked to that, so here's an AdvancedDataGrid that's being printed in my app:

           

                                                          <mx:PrintAdvancedDataGrid dataProvider="{dataRayon}" sortExpertMode="true" id="dataGridRayon" width="100%" itemClick="dispatchEvent(new KpiEvent(DATAGRID_RAYON_CLICK,event));" itemDoubleClick="dispatchEvent(new KpiEvent(DATAGRID_RAYON_CLICK,event));" creationComplete="resizeGridRayon();" >
                                                            <mx:columns>
                                                                      <mx:AdvancedDataGridColumn id="rownumRayon"  width="25"  sortable="false" labelFunction="getRowNumRayon" fontWeight="bold"/>
                                                                      <mx:AdvancedDataGridColumn id="rayonCoRgrp" textAlign="center" width="75" headerText="{resourceManager.getString('rentabilitePanel', 'CODE')}" dataField="co_rgrp_produits" />
                                                                      <mx:AdvancedDataGridColumn textAlign="left" width="240" headerText="{resourceManager.getString('rentabilitePanel', 'SOUS_SECTEURS')}" dataField="libelle" id="hTDataGridRayon" /> 
                                                                      <mx:AdvancedDataGridColumn id="rayonMeVenteHt" textAlign="right" width="100" headerText="{resourceManager.getString('rentabilitePanel', 'MONTANT_VENTE_HT')}" dataField="meVenteHt" formatter="{currencyFormatter}" sortCompareFunction="{function(obj1:Object, obj2:Object):int{return mySortFunc(obj1, obj2, 'meVenteHt');}}"  />
                                                                      <mx:AdvancedDataGridColumn id="rayonMargeAvtDem" textAlign="right" width="75" headerText="{resourceManager.getString('rentabilitePanel', 'MARGE_AVT_DEM')}" dataField="margeAvtDem" formatter="{currencyFormatter}" sortCompareFunction="{function(obj1:Object, obj2:Object):int{return mySortFunc(obj1, obj2, 'margeAvtDem');}}"  />
                                                                      <mx:AdvancedDataGridColumn id="rayonPMargeAvtDem" textAlign="right" width="80" headerText="{resourceManager.getString('rentabilitePanel', 'POUR_MARGE_AVT_DEM')}" dataField="margeAvtDemP" formatter="{pourcentageFormatterFloat}" sortCompareFunction="{function(obj1:Object, obj2:Object):int{return mySortFunc(obj1, obj2, 'margeAvtDemP');}}"  />
                                                                      <mx:AdvancedDataGridColumn id="rayonDemarqueHt" textAlign="right" width="100" headerText="{resourceManager.getString('rentabilitePanel', 'DEMARQUE_HT')}" dataField="demarque" formatter="{currencyFormatterFloat1Dec}" sortCompareFunction="{function(obj1:Object, obj2:Object):int{return mySortFunc(obj1, obj2, 'demarque');}}"  />
                                                                      <mx:AdvancedDataGridColumn id="rayonPDemarqueHt" textAlign="right" width="85" headerText="{resourceManager.getString('rentabilitePanel', 'POUR_DEMARQUE_HT')}" dataField="demarqueP"  formatter="{pourcentageFormatterFloat}" sortCompareFunction="{function(obj1:Object, obj2:Object):int{return mySortFunc(obj1, obj2, 'demarqueP');}}"  />
                                                                      <mx:AdvancedDataGridColumn id="rayonMargeAprDem" textAlign="right" width="100" headerText="{resourceManager.getString('rentabilitePanel', 'MARGE_APR_DEM')}" dataField="margeAprDem" formatter="{currencyFormatter}" sortCompareFunction="{function(obj1:Object, obj2:Object):int{return mySortFunc(obj1, obj2, 'margeAprDem');}}"  />
                                                                      <mx:AdvancedDataGridColumn id="rayonPMargeAprDem" textAlign="right" width="115" headerText="{resourceManager.getString('rentabilitePanel', 'POUR_MARGE_APR_DEM')}" dataField="margeAprDemP" formatter="{pourcentageFormatterFloat}" sortCompareFunction="{function(obj1:Object, obj2:Object):int{return mySortFunc(obj1, obj2, 'margeAprDemP');}}"  />
                                                            </mx:columns>
                                                  </mx:PrintAdvancedDataGrid>
          
          

           

          I also realised I wasn't very clear on the outcome of my doPrint() function. When I said the grid was cut in half, I was talking about half the columns not showing on the printed version, not half the rows. Actually even a column being cut in half. I hope these precisions made my problem a bit clearer and somebody will be able to help me in any way (even just hints).

           

          Thanks for your help.

           

          Regards,

           

          Gudril

          • 2. Re: Problem with printing after migrating from 3.5 to 4.1
            Gudril Level 1

            Nobody has any hint about this problem? I haven't found a solution yet and I don't know what to try anymore

             

            Regards,

             

            Gudril

            • 3. Re: Problem with printing after migrating from 3.5 to 4.1
              Gudril Level 1

              Hello everyone, it's me again!

               

              Well, I managed to make the whole datagrid appear on the printed version. That's more of a workaround I'm not very proud of since I didn't find the root cause of the problem, but it did work, so that'll do for now.

               

              In fact, my PrintAdvancedDataGrid is inside a VBox. So I fixed the VBox's width to 90% and everything fits in now. The weirdest thing is, if I fix the datagrid's width, or the Canvas' one, or the other (H/V)Boxes' or even the component's one (which is a ViewStack in my case), it doesn't work. The VBox's width is the only one that would do the trick.

               

              If anyone ever finds a real explanation as to why the problem I described in this topic appears, I'd be interested. But for now, this little trick will have to do.

               

              Sorry I couldn't bring a better and more complete answer.

               

              Have a nice day!

               

              Gudril

              1 person found this helpful
              • 4. Re: Problem with printing after migrating from 3.5 to 4.1
                Gudril Level 1

                Ok it's me again...

                 

                As I said, I found a workaround for my printing problem. Unfortunately, a problem remains. The landscape mode printing works just fine but the portrait mode is completely broken. How can that be?!? I mean I'm using Flex's functionalities to match the page's width so what gives?

                 

                Well I'm not sure anyone here has had the same problem or has an idea as to why this happens but you never know, so I posted.

                 

                Regards,

                 

                Gudril