Print DataGrid out from Hiden PrintDataGrid
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="initData()">
<mx:Script>
import mx.collections.ArrayCollection;
import mx.printing.FlexPrintJob;
[Bindable]
public var dp:ArrayCollection;
private function initData():void{
this.dp = new ArrayCollection();
for(var i:Number=0; i<10; i++){
this.dp.addItem({row:i,data:"item " + i});
}
}
public function print():void {
var printJob:FlexPrintJob = new FlexPrintJob();
if(printJob.start()){
printJob.addObject(printGrid);
while(true) {
printGrid.nextPage();
if(!printGrid.validNextPage){
printJob.addObject(printGrid);
break;
}
}
printJob.send();
}
}
</mx:Script>
<mx:Button click="print()" label="Print" />
<mx:PrintDataGrid visible="false" id="printGrid" dataProvider="{dp}" height="700" width="600">
<mx:columns>
<mx:DataGridColumn dataField="row" headerText="Row Number" />
<mx:DataGridColumn dataField="data" headerText="Row Data" />
</mx:columns>
</mx:PrintDataGrid>
</mx:Application>
Related examples in the same category