<?
xml version="1.0"
?>
<!-- Custom control to print the DataGrid control on multiple pages. -->
< mx:VBox xmlns:mx ="http://www.adobe.com/2006/mxml" xmlns ="*" backgroundColor ="#FFFFFF"
paddingTop ="50" paddingBottom ="50" paddingLeft ="50" paddingRight ="50" height ="168"
width ="546" >
< mx:Script >
<![CDATA[
import mx.core.*
import mx.collections.ArrayCollection;
[Bindable]
public var pageNumber:Number = 1;
[Bindable]
public var prodTotal:Number = 0;
import mx.printing.*;
public static var footerHeight:Number = 20;
public static var prodIndex:Number;
public static var prodTotal:Number = 0;
public static function doPrint(datap:Object):void {
var printJob:FlexPrintJob = new FlexPrintJob();
if (printJob.start()) {
var thePrintView:FormPrintView = new FormPrintView();
Application.application.addChild(thePrintView);
thePrintView.width=printJob.pageWidth;
thePrintView.height=printJob.pageHeight;
thePrintView.prodTotal = (datap as ArrayCollection).length;
thePrintView.printDataGrid.dataProvider = datap; //设置数据v
thePrintView.showPage("single");
if(!thePrintView.printDataGrid.validNextPage){
printJob.addObject(thePrintView);
}
else{
thePrintView.showPage("first");
printJob.addObject(thePrintView);
thePrintView.pageNumber++;
while(true){
thePrintView.printDataGrid.nextPage();
thePrintView.showPage("last");
if(!thePrintView.printDataGrid.validNextPage) {
printJob.addObject(thePrintView);
break;
}
else{
thePrintView.showPage("middle");
printJob.addObject(thePrintView);
thePrintView.pageNumber++;
}
}
}
Application.application.removeChild(thePrintView);
}
printJob.send();
}
public function showPage(pageType:String):void {
if(pageType == "first" || pageType == "middle") {
footer.includeInLayout=false;
footer.visible = false;
}
if(pageType == "middle" || pageType == "last") {
header.includeInLayout=false;
header.visible = false;
}
if(pageType == "last") {
// Show the footer.
footer.includeInLayout=true;
footer.visible = true;
}
//Update the DataGrid layout to reflect the results.
validateNow();
}
]]>
</ mx:Script >
<!-- The template for the printed page, with the contents for all pages. -->
< mx:VBox width ="100%" horizontalAlign ="left" >
< mx:Label text ="第 {pageNumber}页" color ="#9e9e9e" />
< mx:Label id ="header" text ="通道申请名录" fontWeight ="bold" fontSize ="20" textAlign ="center" width ="100%" />
< mx:HRule width ="100%" height ="1" strokeColor ="#000000" />
</ mx:VBox >
< mx:PrintDataGrid id ="printDataGrid" width ="100%" height ="100%" >
< mx:columns >
< mx:DataGridColumn dataField ="姓名" width ="150" />
< mx:DataGridColumn dataField ="性别" width ="40" />
< mx:DataGridColumn dataField ="学号" width ="80" />
< mx:DataGridColumn dataField ="准考证号" width ="90" />
< mx:DataGridColumn dataField ="生源地" width ="60" />
< mx:DataGridColumn dataField ="身份" width ="75" />
< mx:DataGridColumn dataField ="户口" width ="75" />
< mx:DataGridColumn dataField ="部门" width ="100" />
< mx:DataGridColumn dataField ="财务处是否办理" headerText ="是否办理" />
</ mx:columns >
</ mx:PrintDataGrid >
< mx:VBox width ="100%" horizontalAlign ="left" id ="footer" >
< mx:Spacer height ="100%" />
< mx:HRule width ="100%" height ="1" strokeColor ="#000000" />
< mx:Label text ="总人数:{prodTotal}" />
</ mx:VBox >
</ mx:VBox >
<!-- Custom control to print the DataGrid control on multiple pages. -->
< mx:VBox xmlns:mx ="http://www.adobe.com/2006/mxml" xmlns ="*" backgroundColor ="#FFFFFF"
paddingTop ="50" paddingBottom ="50" paddingLeft ="50" paddingRight ="50" height ="168"
width ="546" >
< mx:Script >
<![CDATA[
import mx.core.*
import mx.collections.ArrayCollection;
[Bindable]
public var pageNumber:Number = 1;
[Bindable]
public var prodTotal:Number = 0;
import mx.printing.*;
public static var footerHeight:Number = 20;
public static var prodIndex:Number;
public static var prodTotal:Number = 0;
public static function doPrint(datap:Object):void {
var printJob:FlexPrintJob = new FlexPrintJob();
if (printJob.start()) {
var thePrintView:FormPrintView = new FormPrintView();
Application.application.addChild(thePrintView);
thePrintView.width=printJob.pageWidth;
thePrintView.height=printJob.pageHeight;
thePrintView.prodTotal = (datap as ArrayCollection).length;
thePrintView.printDataGrid.dataProvider = datap; //设置数据v
thePrintView.showPage("single");
if(!thePrintView.printDataGrid.validNextPage){
printJob.addObject(thePrintView);
}
else{
thePrintView.showPage("first");
printJob.addObject(thePrintView);
thePrintView.pageNumber++;
while(true){
thePrintView.printDataGrid.nextPage();
thePrintView.showPage("last");
if(!thePrintView.printDataGrid.validNextPage) {
printJob.addObject(thePrintView);
break;
}
else{
thePrintView.showPage("middle");
printJob.addObject(thePrintView);
thePrintView.pageNumber++;
}
}
}
Application.application.removeChild(thePrintView);
}
printJob.send();
}
public function showPage(pageType:String):void {
if(pageType == "first" || pageType == "middle") {
footer.includeInLayout=false;
footer.visible = false;
}
if(pageType == "middle" || pageType == "last") {
header.includeInLayout=false;
header.visible = false;
}
if(pageType == "last") {
// Show the footer.
footer.includeInLayout=true;
footer.visible = true;
}
//Update the DataGrid layout to reflect the results.
validateNow();
}
]]>
</ mx:Script >
<!-- The template for the printed page, with the contents for all pages. -->
< mx:VBox width ="100%" horizontalAlign ="left" >
< mx:Label text ="第 {pageNumber}页" color ="#9e9e9e" />
< mx:Label id ="header" text ="通道申请名录" fontWeight ="bold" fontSize ="20" textAlign ="center" width ="100%" />
< mx:HRule width ="100%" height ="1" strokeColor ="#000000" />
</ mx:VBox >
< mx:PrintDataGrid id ="printDataGrid" width ="100%" height ="100%" >
< mx:columns >
< mx:DataGridColumn dataField ="姓名" width ="150" />
< mx:DataGridColumn dataField ="性别" width ="40" />
< mx:DataGridColumn dataField ="学号" width ="80" />
< mx:DataGridColumn dataField ="准考证号" width ="90" />
< mx:DataGridColumn dataField ="生源地" width ="60" />
< mx:DataGridColumn dataField ="身份" width ="75" />
< mx:DataGridColumn dataField ="户口" width ="75" />
< mx:DataGridColumn dataField ="部门" width ="100" />
< mx:DataGridColumn dataField ="财务处是否办理" headerText ="是否办理" />
</ mx:columns >
</ mx:PrintDataGrid >
< mx:VBox width ="100%" horizontalAlign ="left" id ="footer" >
< mx:Spacer height ="100%" />
< mx:HRule width ="100%" height ="1" strokeColor ="#000000" />
< mx:Label text ="总人数:{prodTotal}" />
</ mx:VBox >
</ mx:VBox >
调用方法
<
mx:Button
label
="打印"
click
="{FormPrintView.doPrint(this.myDataGrid.dataProvider)}"
/>