开发者

How to Print in Flex without the UI Components disappearing

开发者 https://www.devze.com 2023-04-01 01:58 出处:网络
I\'m printing from flex, and since I want to customise the jobs such as with margins and a title, I created a UI Component PrintTemplate. I add my stuff to the PrintTemplate and then I print it.

I'm printing from flex, and since I want to customise the jobs such as with margins and a title, I created a UI Component PrintTemplate. I add my stuff to the PrintTemplate and then I print it.

So the code is something like:

printTemplate.addElement(diagram);
addElement(printTemplate);

if (printJob.start()) {
  printJob.addObject(printTemplate);
  printJob.send()
}

The problem is that the UI components disappear from where开发者_如何学Python they should be on the page when you add them to the printTemplate. This looks weird, even though you can add them back later. Is there a way around this - to stop them disappearing when I add them to the template?


A component cannot be the child of two containers at the same time so there's no way you can show them in the original container.

You can, however, take a snapshot of the component you want to print and display it in a BitmapImage as the first child of that component. When printing is done, simply remove the BitmapImage.

    private function displaySnapshot():void
    {
        var bitmapData:BitmapData = new  BitmapData(_displayObject.width,_displayObject.height,false);
        bitmapData.draw(_displayObject,null,null,null,null,true);
        _snapshotImage = new Bitmap(bitmapData);
        _displayObject.addChildAt(_snapshotImage,0);
        _displayObject.visible = false; //optional
    }

    private function removeSnapshot(event:Event):void
    {
        EventDispatcher(event.target).removeEventListener(event.type,arguments.callee);
        _displayObject.parent.removeChild(_snapshotImage);
        _displayObject.visible = true
    }
0

精彩评论

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

关注公众号