Interchangeability is the law of nature. Every matter in the universe, from mass to energy, can be transformed from one form to another. The main advantage of interchangeability is the flexibility to achieve the requirement harnessing the best use of any form. Nevertheless, its true for various aspects in IT as well.

What's the need?

ComponentOne Studio Reports for WinForms provides various components to meet one's reporting, printing, previewing and exporting needs. C1Reports come with two reporting flavors- C1Report and C1PrintDocument, each with its own specific specialty which can be harnessed depending on the user-scenarios. On one hand, C1Report component is a typical reporting control which exposes a rich object model for creating, customizing, loading and saving data-based banded reports. On the other hand, the C1PrintDocument component provides a rich object model allowing to create non-reflowable documents at runtime. For more information on preference and usage of these two components, take a look at the article: From the Realm of Reports and Documents: Preference and Usage. As humans, we need optimized solutions to make the best use of each and every resource. It would be really great if one could use a few features of C1Report with other extensions of C1PrintDocument in order to enhance the usability.

Import C1Report in C1PrintDocument

First thing first, in order to import C1Report into the C1PrintDocument object, we can use the ImportC1Report method of C1PrintDocument. This imports a C1Report definition into the current document and enables us to extend the functionalities on the document level itself.

C1PrintDocument1.ImportC1Report("../../SampleReport.xml", "Sample Report")

After a C1Report has been imported into C1PrintDocument, the document has the following structure:

For a Report Without Grouping

Each section of C1Report can be represented by 'RenderSection' object. For eg. The page footer is represented by a RenderSection object and is assigned to the document's PageLayouts.Default.PageFooter property.

For a Report With Grouping

For each group, a RenderArea is created, and the following object tree is placed between the PageHeader and Footer sections (for two groups):

  1. RenderArea representing the top level group
  2. RenderSection representing GroupHeader1
  3. Detail
  4. RenderSection representing GroupFooter1

Now, we can easily modify/add fields in C1PrintDocument using 'RenderField' object.

Enhancing the Usability with C1PrintDocument

There are a number of functionalities exclusively provided by C1PrintDocument. They can be added to the document after a C1Report has been imported in C1PrintDocument.

  • Use the rich Styling object model of C1PrintDocument for applying styling in existing/new fields of C1Report. For eg. assigning a border to particular side, shadow of field, character spacing, padding etc. The following code snippet can be used to apply styling to an existing field in PageHeader Section of C1Report:
Dim rf1 As New RenderField()  
Dim headerSection As RenderSection = C1PrintDocument1.Body.Children("Header")  
rf1 = headerSection.Children("titleLbl")  
rf1.Style.Shadow.Color = Color.LightGreen  
rf1.Style.Shadow.Transparency = 70  
rf1.Style.Padding.Right = New Unit("1cm")  
rf1.Style.CharSpacing = New Unit("2mm")  
rf1.Style.Borders.Left = New LineDef(New Unit("3mm"), Color.AliceBlue)

Report_inPrintdoc1

  • C1PrintDocument also provides an Anchor and HyperLink feature which can be used to anchor within the current document, within another C1PrintDocument, location within the current document, an external file or a page within the current document. The following code snippet creates a hyperlink to move to the last page of the report:
Dim linkTarget = New C1.C1Preview.C1LinkTargetPage(C1.C1Preview.PageJumpTypeEnum.Last)  
Dim rf2 As New RenderField()  
rf2 = headerSection.Children("Field4")  
Dim hyper As New C1Hyperlink()  
hyper.LinkTarget = linkTarget  
rf2.Hyperlink = hyper

c1ReportInDoc

You can do a lot more than just modifying the styling. Have fun!

Working Sample

Download Sample