flex分页打印操作实现代码


Flex #flexprintjob #分页打印2014-04-10 09:51

1.使用FlexPrintJob进行打印操作


1.如果没有分页和下拉框的时候


public function doPrint() : void {
    var printer: FlexPrintJob = new FlexPrintJob();
    if (printer.start()) {
        printer.addObject(body);
        printer.send();
    }
}这个方法即可下面的可以使用,由于我使用的是Flex3,
Flex3里面没有标签“PrintDataGrid”,只有“PrintAdvancedDataGrid”。所以下面就使用(“PrintAdvancedDataGrid”,“AdvancedDataGrid”,“DataGrid”)这三种方式,切记上面的方式只适合于单个页面(数据较少)且没有下拉框


< mx: PrintAdvancedDataGrid id = "body"x = "188"y = "232" > <mx: columns > <mx: AdvancedDataGridColumn dataField = "username" / ><mx: AdvancedDataGridColumn dataField = "password" / ></mx:columns> 
</mx: PrintAdvancedDataGrid >


--------------------------------------------------------------------------------------


<mx: AdvancedDataGrid id = "body"x = "188"y = "232" > <mx: columns > <mx: AdvancedDataGridColumn dataField = "username" / ><mx: AdvancedDataGridColumn dataField = "password" / ></mx:columns> 
</mx: AdvancedDataGrid >


-----------------------------------------------------------------------------------------


<mx: DataGrid id = "body"x = "188"y = "232" > <mx: columns > <mx: DataGridColumn dataField = "username" / ><mx: DataGridColumn dataField = "password" / ></mx:columns> 
</mx: DataGrid >


----------------------------------------------------------------------------------------------------------------------------------------------------------


如果要使用分页效果,则必须使用标签"PrintAdvancedDataGrid" (Flex3中的标签)才能够实现分页效果


private
function doPrint() : void {
    var PrintJob: FlexPrintJob = new FlexPrintJob();
    if (PrintJob.start()) {
        addChild(body);
        //设置的打印视图属性
        while (true) {
            PrintJob.addObject(body);
            if (body.validNextPage) {
                body.nextPage();
            } else {
                break;
            }
        }
    }
    PrintJob.send();
}


这个方法,所对应的标签是:


< mx: PrintAdvancedDataGrid id = "body"x = "188"y = "232" > <mx: columns > <mx: AdvancedDataGridColumn dataField = "username" / ><mx: AdvancedDataGridColumn dataField = "password" / ></mx:columns> 
</mx: PrintAdvancedDataGrid > 


相关文章

粤ICP备11097351号-1