首页 > 网站 > WEB开发 > 正文

26.11.打印页眉和页脚

2024-04-27 13:52:39
字体:
来源:转载
供稿:网友
26.11.1. 问题
我想打印出页眉和页脚
26.11.2. 解决办法
创建打印渲染器组件控制页面布局
26.11.3. 讨论
结合打印渲染器的PrintDataGrid比PrintDataGrid自身具备更多的布局控制能力。常见的任务就是打印页眉和页脚。这个技术涉及是否在布局中包含页眉和页脚以及PrintDataGrid的validNextPage属性的测试结果。下面的代码,HeaderFooterPrintRenderer.mxml,定义了一个打印渲染器生成多页打印内容,包括在适当位置的页眉和页脚:
+展开
-XML
<?xml version="1.0"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"
backgroundColor="#ffffffhorizontalAlign="center">

<mx:Script>
<![CDATA[
public function startJob():void
{
//Try to print this on a single page
header.visible = true;
header.includeInLayout = true;
footer.visible = true;
footer.includeInLayout = true;
this.validateNow();
if (printGrid.validNextPage)
{
//The grid is too big to fit on a single page
footer.visible = false;
footer.includeInLayout = false;
this.validateNow();
}
}
public function nextPage():Boolean
{
header.visible = false;
header.includeInLayout = false;
printGrid.nextPage();
footer.visible = !printGrid.validNextPage;
footer.includeInLayout = !printGrid.validNextPage;
this.validateNow();
return printGrid.validNextPage;
}

]]>
</mx:Script>
<mx:DateFormatter id="formatterformatString="M/D/YYYY" />
<mx:Canvas id="headerheight="80width="100%">
<mx:Label text="Population by State"
fontSize="24"
color="0x666666"
horizontalCenter="0"
verticalCenter="0"
width="100%"
textAlign="center" />

</mx:Canvas>
<mx:VBox height="100%width="80%">
<mx:PrintDataGrid id="printGridwidth="100%"
height="100%">

<mx:columns>
<mx:DataGridColumn dataField="@name"
headerText="State" />

<mx:DataGridColumn dataField="@population"
headerText="Population"/>

</mx:columns>
</mx:PrintDataGrid>
</mx:VBox>
<mx:DateFormatter id="formatformatString="m/d/yyyy" />
<mx:Canvas id="footerheight="80width="100%">
<mx:Label text="{formatter.format(new Date())}"
left="20bottom="5" />

</mx:Canvas>
</mx:VBox>
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表