开发者

How do I Print a dynamically created Flex component/chart that is not being displayed on the screen?

I have a several chart components that I have created in Flex. Basically I have set up a special UI that allows the user to select which of these charts they want to print. When they press the print button each of the selected charts is created dynamically then added to a container. Then I send this container off to FlexPrintJob.

i.e.

    private function prePrint():void
    {
        var printSelection:Box = new Box();
        printSelection.percentHeight = 100;
        printSelection.percentWidth = 100;
        printSelection.visible = true;

        if (this.chkMyChart1.selected)
        {
            var rptMyChart1:Chart1Panel = new Chart1Panel();
            rptMyChart1.percentHeight = 100;
            rptMyChart1.percentWidth = 100;
            rptMyChart1.visible = true;
            printSelection.addChild(rptMyChart1);
        }

        print(printSelection);
    }


    private function print(container:Box):void
    {
        var job:FlexPrintJob;

        job = new FlexPrintJob();

        if (job.start()) {
            job.addObject(container, FlexPrintJobScaleType.MATCH_WIDTH);
            job.send();
        }

    }

This code works fine if the chart is actually displayed somewhere on the page but adding it dynamically as shown above does not. The print dialog will appear but nothing happens when I press OK.

So I really have two questions:

  1. Is it possible to print flex components/charts when they are not visible on the screen?
  2. If so, how do I do it / what am I doing wrong?

UPDATE:

Well, at least one thing wrong is my use of the percentages in the width and height. Using percentages doesn't really make sense when the Box is not contained in another object. Changing the height and width to fixed values actually allows the printing to progress and solves my initial problem.

    printSelection.height = 100;
    printSelection.width = 100;

But a new problem arises in that instead of seeing my chart, I see a black box instead. I have previously resolved this issue by setting the background colour of the chart to #FFFFFF but this doesn't seem to be working this time.

UPDATE 2:

I have seen some examples on the adobe site that add the container to the application but don't include it in the layout. This looks like the way to go.

i.e.

    printSelection.includeInLayout = false;
    addChild开发者_如何学运维(printSelection);


Your component has to be on the stage in order to draw its contents, so you should try something like this:

printSelection.visible = false;

application.addChild(printSelection);

printSelection.width = ..;

printSelection.height = ...;

... then do the printing


i'm not completely sure, but in one of my application I have to print out a complete Tab Navigator and the only method i have found to print it is to automatically scroll the tabnavigator tab in order to show the component on screen when i add them to the printjob.

In this way they are all printed. Before i created the tabnaviagotr scrolling the print (to PDF) result was a file with all the pages of the tab but only the one visible on screen really printed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜