首先要導(dǎo)入 import mx.printing.FlexPrintJob;
import mx.printing.PrintAdvancedDataGrid;
1.使用FlexPrintJob進(jìn)行打印操作
1.如果沒有分頁(yè)和下拉框的時(shí)候
復(fù)制代碼 代碼如下:
public function doPrint():void{
var printer:FlexPrintJob = new FlexPrintJob();
if(printer.start()){
printer.addObject(body);
printer.send();
}
}
這個(gè)方法即可 下面的可以使用,由于我使用的是Flex3,Flex3里面沒有標(biāo)簽“PrintDataGrid”,只有“PrintAdvancedDataGrid”。所以下面就使用(“PrintAdvancedDataGrid”,“AdvancedDataGrid ”,“DataGrid ”)這三種方式,切記上面的方式只適合于單個(gè)頁(yè)面(數(shù)據(jù)較少)且沒有下拉框
復(fù)制代碼 代碼如下:
mx:PrintAdvancedDataGrid id="body" x="188" y="232">
mx:columns>
mx:AdvancedDataGridColumn dataField="username"/>
mx:AdvancedDataGridColumn dataField="password"/>
/mx:columns>
/mx:PrintAdvancedDataGrid>
--------------------------------------------------------------------------------------
[/code]
mx:AdvancedDataGrid id="body" x="188" y="232">
mx:columns>
mx:AdvancedDataGridColumn dataField="username"/>
mx:AdvancedDataGridColumn dataField="password"/>
/mx:columns>
/mx:AdvancedDataGrid>
[/code]
-----------------------------------------------------------------------------------------
復(fù)制代碼 代碼如下:
mx:DataGrid id="body" x="188" y="232">
mx:columns>
mx:DataGridColumn dataField="username"/>
mx:DataGridColumn dataField="password"/>
/mx:columns>
/mx:DataGrid>
----------------------------------------------------------------------------------------------------------------------------------------------------------
如果要使用分頁(yè)效果,則必須使用標(biāo)簽"PrintAdvancedDataGrid"(Flex3中的標(biāo)簽)才能夠?qū)崿F(xiàn)分頁(yè)效果
復(fù)制代碼 代碼如下:
private function doPrint():void{
var PrintJob:FlexPrintJob = new FlexPrintJob();
if(PrintJob.start()){
addChild(body);
//設(shè)置的打印視圖屬性
while(true){
PrintJob.addObject(body);
if(body.validNextPage){
body.nextPage();
}else{
break;
}
}
}
PrintJob.send();
}
這個(gè)方法,所對(duì)應(yīng)的標(biāo)簽是:
復(fù)制代碼 代碼如下:
mx:PrintAdvancedDataGrid id="body" x="188" y="232">
mx:columns>
mx:AdvancedDataGridColumn dataField="username"/>
mx:AdvancedDataGridColumn dataField="password"/>
/mx:columns>
/mx:PrintAdvancedDataGrid>