Skip to main content
Participant
March 30, 2010
Question

How to print a spark List with customs ItemRenderer?

  • March 30, 2010
  • 1 reply
  • 1188 views

Hye,

I made a component which contains a spark List with custom ItemRenderers and I like to print it. Is there any solution to do it with all the data print on different pages and the correct ItemRenderer for each one.

Thank you for your help...

This topic has been closed for replies.

1 reply

Participant
November 10, 2010

I too have this same question.  The itemRenderer I'm using is actually a graph.  Right now I'm sending the entire spark list to the print job as a UIComponent, but it's only printing graph labels for the visible portion of the list (the list is long and has a scrollbar when being viewed).  The rest of the list is printing, but devoid of those labels.

- d.

EDIT:  This is what I did to solve this problem.  You can print a list by sending that list as a UIComponent to a print job method.  To resize the list (if it's scrollable) you need to reference the list's dataGroup to get the number of visual elements in that list.  From there you can resize a copy of your list to the total combined height of ALL the items in the list (I added 10 to that total just to make sure the scrollbar didn't show).  Then set the height of your copied list to that height and add the copied list to the print job and print.  End of story - worked like a charm for me.  Here's the method I used for printing:

private function doPrint(obj:UIComponent):void
            {
                var newList:spark.components.List = obj as spark.components.List;
                // calculate height
                var totalHeight:Number = 0;
                for(var i:int=0;i<newList.dataGroup.numElements;i++){
                    totalHeight += newList.dataGroup.getElementAt(i).height;
                }
                newList.height = totalHeight + 10;
               
                var job:FlexPrintJob = new FlexPrintJob();
               
                job.printAsBitmap = false;
               
                if (job.start() != true) return;
                job.printAsBitmap = false;
               
                job.addObject(newList, FlexPrintJobScaleType.SHOW_ALL);
               
                job.send();
               
            }

Participating Frequently
December 29, 2010

DouginOr,

The solution you posted would be wonderful, but I am unable to get it to work.  Were you using a beta version of Flex 4 at the time this was posted?  If so, do you have a current solution.

Your code is casting a DataGroup to spark.components.List, but DataGroup is not a subclass of List.  That line is returning a null List.  Your code also shows that list as having a property called 'dataGroup'., but there is no such property in the List class in Flex 4.

My apologies, if my question seems too direct, but I have been spending hours on a variety of solutions to print a report that is implemented on the screen as three nested item renderers.  It seems that the only solution might be to write entirely different code that loops through all of the model objects and instantiates and adds the display information from each object.  The duplication of code to display the same thing on paper that it already presents on the screen seems unfortunate.  Your solution would solve the problem.  Hopefully, you have a variant that will work in the production release version of Flex 4.

Gary