C1PrintDocument component allows you to create complex documents that can be printed, previewed or exported to a number of external formats. In this blog, I would like to discuss a couple of frequently asked questions for C1PrintDocument, that is :

  1. Customize PageFooter of C1PrintDocument
  2. Display Borders in C1PrintDocument

C1PrintDocument offers the ability to display a footer on each page for a summarized view. These can be customized using PageLayout.PageFooter property. For demonstration, lets consider a scenario where user wants to display 'Continued' text in the document except the last page. This is a two step process :

  • Define PageLayour Object for the C1PrintDocument
  • Set PageFooter property conditionally

Step1 : Define the PageLayout Object The first step is to define a PageLayout that can be used to assign a PageFooter to the pages in the C1PrintDocument as shown in the code below:

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()

Notice that the PrintFooterOnLastPage property has been set to false in order to indicate that the PageFooter should not be printed on the last page of the document. Step 2 : Set PageFooter Property Conditionally After defining the PageLayout, the next step is to set the PageFooter property to "Continued.." conditionallly. Also, we need to make sure that the message does not appear when there is only one page in the document. To do this, count the total number of pages and hide the PageFooter on the first page using PrintFooterOnFirstPage property if there is only one page in the document. Here is the code snippet for accomplishing the above :

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

Display Borders in C1PrintDocument

To display borders in C1PrintDocument, we need to add an empty RenderArea to the size of the document and set the Style.Borders.All property to LineDef.Default.

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

However, the borders can also be displayed around the text rendered in the cells of a RenderTable.

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)

Result Download Sample C# Download Sample VB