C1PrintDocument提示和技巧

发布时间:2014/07/27 00:07 发布者:Alice

返回博客中心

C1PrintDocument允许创建复杂的documents用来打印,预览或是多种格式输出。本文讨论C1PrintDocument中经常被问到的问题。

1.自定义C1PrintDocument的PageFooter

2.在C1PrintDocument里显示边框。

自定义C1PrintDocument的PageFooter

C1PrintDocument提供显示内容在每页页脚的能力,这些可以通过PageLayouts.PageFooter属性自定义。

假设我们要在非最后一页显示“Continued”文字,这里需要两步;

1.定义PageLayout对象

第一个首先要定义PageLayout,设置一个PageFooter,并且添加到C1PrintDocument的页面,代码如下:

Dim pagelayout As New PageLayout()
Dim pagefooter As New RenderText()
pagefooter.Text = " Continued to Next Page..."
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属性隐藏在第一页的页脚。

代码片段如下:

If C1PrintDocument1.Pages.Count = 1 Then
   C1PrintDocument1.PageLayouts.PrintFooterOnFirstPage = False
End If

 

在C1PrintDocument里显示边框

为了实现这个效果,我们需要添加一个空的RenderArea到doment的size中,然后设置Style.Borders.All属性为LineDef.Default。

Dim overlay As New RenderArea()
overlay.Width = "100%"
overlay.Height = "100%"
overlay.Style.Borders.All = LineDef.Default
C1PrintDocument1.PageLayout.Overlay = overlay

 

这样,边框就可以显示在RenderTable的单元格里的text rendered的周围。代码如下:

Dim rtxt As New RenderText("center me!")
rtxt.Style.Borders.All = New LineDef(Color.Red)
rtxt.Width = "2cm"
Dim ra As New RenderArea()
ra.Stacking = StackingRulesEnum.BlockLeftToRight
ra.Style.FlowAlignChildren = FlowAlignEnum.Center
ra.Children.Add(rtxt)
rtTbl.Cells(1, 1).RenderObject = ra
C1PrintDocument1.Body.Children.Add(rtTbl)

 

如上所述的两种效果,可以通过下面的图片展示出来:

 

本文的源代码如下:

C1PrintDocument_Customizations_VB.zip (30.02 kb)


关于葡萄城

赋能开发者!葡萄城是专业的集开发工具、商业智能解决方案、低代码开发平台于一身的软件和服务提供商,为超过 75% 的全球财富 500 强企业提供服务。葡萄城专注控件软件领域30年,希望通过模块化的开发控件、灵活的低代码应用开发平台等一系列开发工具、解决方案和服务,帮助开发者快速响应复杂多变的业务需求,最大程度地发挥开发者的才智和潜能,让开发者的 IT 人生更从容更美好。

了解详情,请访问葡萄城官网