我正在尝试使用flex printjob从datagrid打印数据。网格中大约有40行填充了数据。
但是,当我尝试打印时,该应用程序崩溃,但是打印了一些页面。
这是我的代码:
protected function openPrintDialogMonth():void {
doPrintingMonth();
}
protected function doPrintingMonth():void {
var printjob2:FlexPrintJob;
var printTemplate:printTemplate = new printTemplate();
var printDataGrid:PrintDataGrid;
printjob2 = new FlexPrintJob();
if( printjob2.start() )
{
var currentYear:Date = new Date();
var dataArray:Array = new Array();
trace( "Width/Height:", printjob2.pageWidth, "/", printjob2.pageHeight );
printDataGrid = new PrintDataGrid();
printTemplate.width = 1368;
printTemplate.height = 800;
printTemplate.data = gridReport.dataProvider;
printTemplate.editData();
printTemplate.year = String(currentYear.getFullYear());
printTemplate.printDataGrid.columns = gridReport.columns;
printTemplate.printDataGrid.columnWidth = gridReport.columnWidth;
printTemplate.printDataGrid.visible = true;
printTemplate.printDataGrid.showHeaders = true;
printTemplate.printDataGrid.sizeToPage = true;
printTemplate.scaleX = 1.00;
printTemplate.validateNow();
this.addElement( printTemplate );
if( !printTemplate.printDataGrid.validNextPage )
{
printjob2.addObject( printTemplate,FlexPrintJobScaleType.MATCH_WIDTH);
this.removeElement( printTemplate );
}
else
{
printjob2.addObject( printTemplate,FlexPrintJobScaleType.MATCH_WIDTH);
this.removeElement( printTemplate );
while( true )
{
printTemplate.printDataGrid.nextPage();
printjob2.addObject( printTemplate,FlexPrintJobScaleType.MATCH_WIDTH);
if( !printTemplate.printDataGrid.validNextPage )
break;
}
}
printjob2.send();
}
}
最佳答案
今天,在使用Adobe Air的Flash中遇到了相同的问题。就我而言,在开始打印作业之前,我必须先将displayobject添加到舞台上。将其添加到显示列表将强制重绘,这可能是printjob所需的。