Here is an example of how to print a component to disk using Flex.
The basic idea is to grab the component as a new BitmapData Object, covert that to a PNG ByteArray and then use a FileReference to save the ByteArray to disk.
As you can see in the example here, you can pretty much output any object - and it won’t get clipped by the scrollbars on the browser page.
Here is the relevant code (the demo has view source enabled for full source code):
private function writeDGToDisk ( ): void {
var fr:FileReference = new FileReference();
var encoder:PNGEncoder = new PNGEncoder();
var bitmapData : BitmapData = new BitmapData(taskDataGrid.width, taskDataGrid.height, true, 0x000000);
bitmapData.draw(taskDataGrid);
var byteArrayData:ByteArray = encoder.encode(bitmapData);
fr.save(byteArrayData,"datagrid.jpg");
}
Enjoy.
Caspar










Posted by charmer on October 7, 2009 at 7:06 pm
