C1PrintDocument : Display Text at Page Bottom

C1Report has a property PrintAtBottom which allows to print bottom bound text. This property and it's implementation is discussed in this blog. However, there is no such property available in C1PrintDocument through which user can display a bottom bound text at the end of the document. A simple approach to achieve this is to assign a new Page Layout to the last page and add the desired text as the Page Footer in it (C1PrintDocument can have different page layouts for different pages). Following code is used to add a new PageLayout to the last page and add a tearoffSpace object to display the text at page bottom :

' last page layout:  
doc.PageLayouts.LastPage = New PageLayout()  
doc.PageLayouts.LastPage.PageFooter = New RenderEmpty  

' sample document body (before tear-off):  
For i = 0 To 355  
     doc.Body.Children.Add(New RenderText(String.Format("Document body, line {0}.", i)))  
Next  

' tear-off spacer:  
' (absolutely positioned objects are not part of objects flow, so to make sure  
' document content does not overlap absolutely positioned tearoff, this is needed)  
Dim tearoffSpace As New RenderEmpty  
tearoffSpace.Height = "3cm"  
' VisibilityEnum.Hidden does not display the object but leaves the space for it:  
tearoffSpace.Visibility = VisibilityEnum.Hidden  
doc.Body.Children.Add(tearoffSpace)  

' tear-off - absolutely positioned:  
Dim tearoff As New RenderTable  
tearoff.Cells(0, 0).Text = "This is New Footer for the last page"  
tearoff.Style.BackColor = Color.Aqua  
tearoff.Height = "5cm"  
tearoff.Style.Borders.Top = LineDef.Default  
tearoff.Y = "page.bottom - 5cm"  
doc.Body.Children.Add(tearoff)

If you observe the above code, a blank space is also added in the layout of the last page before adding the bottom bound text. This is done to avoid the overlapping of the document's content and the page footer of the last page. Note : The size of the RenderEmpty object can be set as per your requirement. The C1PrintDocument will look something like the image below : A complete Sample-CSharp/Sample-VB demonstrating this approach is attached.

GrapeCity

GrapeCity Developer Tools
comments powered by Disqus