ComponentOnePrintDocument提示和技巧
C1PrintDocument允许创建复杂的documents用来打印,预览或
是多种格式输出。本文讨论C1PrintDocument中经常被问到的问
题。
1.自定义C1PrintDocument的PageFooter
2.在C1PrintDocument里显示边框。
自定义C1PrintDocument的PageFooter
C1PrintDocument提供显示内容在每页页脚的能力,这些可以通
过PageLayouts.PageFooter属性自定义。
假设我们要在非最后一页显示“Continued”文字,这里需要两
步;
1.定义PageLayout对象
第一个首先要定义PageLayout,设置一个PageFooter,并且添
加到C1PrintDocument的页面,代码如下:
DimpagelayoutAsNewPageLayout()
DimpagefooterAsNewRenderText()
pagefooter.Text="ContinuedtoNextPage..."
pagefooter.Style.Borders.All=LineDef.Default
pagefooter.Style.FontBold=True
pagefooter.Style.TextColor=Color.Maroon
pagelayout.PageFooter=pagefooter
C1PrintDocument1.PageLayouts.PrintFooterOnLastPage=False
C1PrintDocument1.PageLayout.PageFooter=pagelayout.PageFooter
C1PrintDocument1.Generate()
注意:PrintFooterOnLastPage属性要设置为False,这样子
PageFooter才能不打印到document的最后一页。
2.设置PageFooter属性的条件
在定义PageFooter之后,下一步就是设置PageFooter属性为
“Continued..”。而且我们需要确保如果只有一页,这个文字不会出
现在页面。这样,就需要计算页数,如果仅有一页的时候,使用
PrintFooterOnFirstPage属性隐藏在第一页的页脚。
代码片段如下:
IfC1PrintDocument1.Pages.Count=1Then
C1PrintDocument1.PageLayouts.PrintFooterOnFirstPage=False
EndIf
在C1PrintDocument里显示边框
为了实现这个效果,我们需要添加一个空的RenderArea到
doment的size中,然后设置Style.Borders.All属性LineDef.Default。
DimoverlayAsNewRenderArea()
overlay.Width="100%"
overlay.Height="100%"
overlay.Style.Borders.All=LineDef.Default
C1PrintDocument1.PageLayout.Overlay=overlay
这样,边框就可以显示在RenderTable的单元格里的text
rendered的周围。代码如下:
DimrtxtAsNewRenderText("centerme!")
rtxt.Style.Borders.All=NewLineDef(Color.Red)
rtxt.Width="2cm"
DimraAsNewRenderArea()
ra.Stacking=StackingRulesEnum.BlockLeftToRight
ra.Style.FlowAlignChildren=FlowAlignEnum.Center
ra.Children.Add(rtxt)
rtTbl.Cells(1,1).RenderObject=ra
C1PrintDocument1.Body.Children.Add(rtTbl)
如上所述的两种效果,可以通过下面的图片展示出来:
|
|