Class HeaderFooterReport
Represents a PDF report with customizable headers, footers, and content. This class provides a comprehensive set of properties and methods for managing page layout, fonts, margins, header, footer and adding content such as images and text in a structured manner. This class can be used as a template for a standard report with user-customizable layout.
public class HeaderFooterReport : PdfReport
- Inheritance
-
HeaderFooterReport
- Inherited Members
Examples
using Root.ReportNet.Pdf;
public class ExampleReport : HeaderFooterReport {
public ExampleReport() {
Title.Text = "Example Report";
}
protected override void Create() {
AddContent(new RepString(TextFont, "Here is some content."));
}
}
Remarks
This class is intended to allow program users to adapt the page layout for their reports themselves via dialog or configuration.
The margins and the header and footer objects can be flexibly positioned and parameterized.
Possible procedure for creating a report:
- Create a new class derived from
HeaderFooterReport
. -
Set the properties of the
HeaderFooterReport
in the constructor so that they fit your report. The properties can be set directly using code for this report or they can be taken from an input mask or a configuration dataset. After calling the constructor, an empty page is available. It can be referenced via the property CurPage. -
Overwrite the method Create() and create the report content in it.
- Create a new page with method CreateNewPage(). This method creates a new page, adds it to the report, and creates the header and footer.
- The property CurY contains the start position for the report content.
-
Create the report objects and add them to the report.
Method AddContent(RepObject, AddContentOptions) adds them at the current vertical position (CurY).
When the page is full, a page break occurs automatically.
Report objects can also be positioned absolutely (e.g.CurPage.Add(x, y, repString)
. In this case, there is no automatic page break. - Finally, the footers will be completed because the number of pages is not known until the end of the report.
Fonts
Default font definitions and the corresponding font:Default font definitions | Default font |
---|---|
FontDef, font Helvetica | TextFont, size 10 |
BoldFontDef, font Helvetica-Bold | BoldTextFont, size 10 |
Margins
The margins can be set separately on the left and right. The property ContentMarginTop determines the position of the beginning of the report content (distance from the bottom position of the header to the top of the content). The property ContentMarginBottom determines the bottom position of the report content (distance from the bottom of the page to the bottom position of the content). All positioning can be set in points or millimetres.Constructors
HeaderFooterReport(PageSize, PageOrientation)
Initializes a new instance of the HeaderFooterReport class, setting up default fonts, margins and header/footer elements.
public HeaderFooterReport(PageSize pageSize = PageSize.A4, PageOrientation pageOrientation = PageOrientation.Portrait)
Parameters
pageSize
PageSizeDefault page size of the report.
pageOrientation
PageOrientationDefault page orientation of the report.
Remarks
This constructor initializes the report with default settings, including:
- Default fonts for text and bold text
- Default margins for the left, right, top and bottom of the content
- Default header/footer elements such as logo, company name, title, subtitle, comment, description, footnote and footer sections
- See Also
Properties
AvailableContentHeight
Gets the height of the area that is currently available for the content.
public double AvailableContentHeight { get; }
Property Value
- double
The available content height in points.
Remarks
It is the same value as: CurY - CurContentBottom.
- See Also
AvailableContentHeightMM
Gets the height of the area that is currently available for the content.
public double AvailableContentHeightMM { get; }
Property Value
- double
The available content height in millimeters.
Remarks
It is the same value as: CurYmm - CurContentBottomMM.
- See Also
BoldFontDef
Gets or sets the bold font definition for the report.
The default bold font definition is Helvetica-Bold
.
public FontDef BoldFontDef { get; set; }
Property Value
BoldTextFont
Gets or sets the bold text font property for the report.
The default bold text font property is Helvetica-Bold
, size 10.
public FontProp BoldTextFont { get; set; }
Property Value
Comment
Gets or sets the comment of the report.
public UserPlaceableText Comment { get; set; }
Property Value
- UserPlaceableText
The comment as a UserPlaceableText object, not nullable.
Remarks
The reference point for the placement of the comment is (MarginLeft / Page.Height). The default x-coordinate of the comment relative to the reference point is 0, alignment None, i.e. the comment will be placed at the left margin. The default y-coordinate of the comment is relative to the bottom of the Subtitle, -5 millimeters, alignment Top, i.e. the comment will be placed 5 millimeters below the subtitle. The width of the text is limited to 70% of the ContentWidth.
- See Also
CompanyName
Gets or sets the company name.
public UserPlaceableText CompanyName { get; set; }
Property Value
- UserPlaceableText
The company name object, not nullable.
Remarks
The reference point for the placement of the company name is (MarginLeft / Page.Height). The default coordinates of the company name relative to the reference point are (ContentWidth / -15 mm), alignment Right / Top, i.e. the company name will be placed right-aligned to the right margin. The width of the text is limited to 30% of the ContentWidth.
- See Also
ContentMarginBottom
Gets or sets the margin between the footer and the content in points. The default value is 3 millimeters.
public double ContentMarginBottom { get; set; }
Property Value
- double
The content bottom margin in points.
- See Also
ContentMarginBottomMM
Gets or sets the margin between the footer and the content in millimeters. The default value is 3 millimeters.
public double ContentMarginBottomMM { get; set; }
Property Value
- double
The content bottom margin in millimeters.
- See Also
ContentMarginTop
Gets or sets the margin between the header and the content in points. The default value is 3 millimeters.
public double ContentMarginTop { get; set; }
Property Value
- double
The content top margin in points.
- See Also
ContentMarginTopMM
Gets or sets the margin between the header and the content in millimeters. The default value is 3 millimeters.
public double ContentMarginTopMM { get; set; }
Property Value
- double
The content top margin in millimeters.
- See Also
ContentWidth
Gets the width of the content area in points.
public double ContentWidth { get; }
Property Value
- double
The content width in points.
- See Also
ContentWidthMM
Gets the width of the content area in millimeters.
public double ContentWidthMM { get; }
Property Value
- double
The content width in millimeters.
- See Also
CurContentBottom
Gets the bottom position of the content area in points.
public double CurContentBottom { get; }
Property Value
- double
The content bottom position in points.
Remarks
It is the same value as: FooterTop + ContentMarginBottom + height of Footnote. The footnote takes up space from the content and reduces it.
- See Also
CurContentBottomMM
Gets the bottom position of the content area in millimeters.
public double CurContentBottomMM { get; }
Property Value
- double
The content bottom position in millimeters.
Remarks
It is the same value as: FooterTopMM + ContentMarginBottomMM + height of Footnote. The footnote takes up space from the content and reduces it.
- See Also
CurContentTop
Gets the top position of the content area in points.
public double CurContentTop { get; }
Property Value
- double
The content top position in points.
Remarks
This value is valid after the header has been created, it then has the same value as CurY.
- See Also
CurContentTopMM
Gets the top position of the content area in millimeters.
public double CurContentTopMM { get; }
Property Value
- double
The content top position in millimeters.
Remarks
This value is valid after the header has been created, it then has the same value as CurYmm.
- See Also
CurPage
Gets the current page of the report.
public Page CurPage { get; }
Property Value
Remarks
This property will be set in the constructor HeaderFooterReport(PageSize, PageOrientation) and in method CreateNewPage().
CurY
Gets or sets the current Y position on the page in points, used for content placement.
public double CurY { get; set; }
Property Value
- double
The current y-coordinate in points.
Remarks
This property will be set to the bottem position of the header (i.e. top position of content) in method CreateNewPage().
CurYmm
Gets or sets the current Y position on the page in millimeters, used for content placement.
public double CurYmm { get; set; }
Property Value
- double
The current y-coordinate in millimeters.
Remarks
This property will be set to the bottem position of the header (i.e. top position of content) in method CreateNewPage().
Description
Gets or sets the description of the report.
public UserPlaceableText Description { get; set; }
Property Value
- UserPlaceableText
The description as a UserPlaceableText object, not nullable.
Remarks
The reference point for the placement of the description is (MarginLeft / Page.Height). The default x-coordinate of the description relative to the reference point is 0, alignment None, i.e. the description will be placed at the left margin. The default y-coordinate of the description is relative to the bottom of the Comment, -4 millimeters, alignment Top, i.e. the description will be placed 4 millimeters below the comment. The width of the text is limited to 70% of the ContentWidth.
- See Also
FontDef
Gets or sets the standard font definition for the report.
The default font definition is Helvetica
.
public FontDef FontDef { get; set; }
Property Value
FooterCenter
Gets or sets the center footer.
public UserPlaceableText FooterCenter { get; set; }
Property Value
- UserPlaceableText
The center footer as a UserPlaceableText object, not nullable.
Remarks
The reference point for the placement of the center footer text is (MarginLeft / FooterTop). The default coordinates of the center footer text relative to the reference point are (ContentWidth/2 / -2 mm), alignment Center / Top, i.e. the text will be placed at the middle of the content, 2 millimeters below the top position of the footer. The width of the text is limited to a third of the ContentWidth.
- See Also
FooterLeft
Gets or sets the left footer.
public UserPlaceableText FooterLeft { get; set; }
Property Value
- UserPlaceableText
The left footer as a UserPlaceableText object, not nullable.
Remarks
The reference point for the placement of the left footer text is (MarginLeft / FooterTop). The default coordinates of the left footer text relative to the reference point are (0 / -2 mm), alignment Left / Top, i.e. the text will be placed at the left margin, 2 millimeters below the top position of the footer. The width of the text is limited to a third of the ContentWidth.
- See Also
FooterRight
Gets or sets the right footer.
public UserPlaceableText FooterRight { get; set; }
Property Value
- UserPlaceableText
The right footer as a UserPlaceableText object, not nullable.
Remarks
The reference point for the placement of the right footer text is (MarginLeft / FooterTop). The default coordinates of the center footer text relative to the reference point are (ContentWidth / -2 mm), alignment Right / Top, i.e. the text will be placed at the right margin, right-aligned, 2 millimeters below the top position of the footer. The width of the text is limited to a third of the ContentWidth.
- See Also
FooterSeparatorPen
Gets or sets the pen of the footer separator line. The default pen is black and the width is 0.5 pixel. If this value is null, no separator line will be created.
public PenProp? FooterSeparatorPen { get; set; }
Property Value
- PenProp
The footer separator pen, nullable.
- See Also
FooterTop
Gets or sets the top position of the footer in points. The default value is 15 millimeters.
public double FooterTop { get; set; }
Property Value
- double
The footer top position in points.
- See Also
FooterTopMM
Gets or sets the top position of the footer in millimeters. The default value is 15 millimeters.
public double FooterTopMM { get; set; }
Property Value
- double
The footer top position in millimeters.
- See Also
Footnote
Gets or sets the footnote of the report.
public UserPlaceableText Footnote { get; set; }
Property Value
- UserPlaceableText
The footnote as a UserPlaceableText object, not nullable.
Remarks
The reference point for the placement of the footnote is (MarginLeft / FooterTop).
The default coordinates of the footnote relative to the reference point are (0 / 2 mm), alignment Left / Bottom, i.e. the footnote will be placed at the left margin, 2 millimeters above the top position of the footer.
The width of the text is limited to the ContentWidth.
The footnote text must not contain any tags like <DateTime>
, <PageNumber>
or <NumberOfPages>
.
- See Also
IsContentEmpty
Determines whether the content area is empty.
public bool IsContentEmpty { get; }
Property Value
Logo
Gets or sets the logo of the report.
public UserPlaceableImage Logo { get; set; }
Property Value
- UserPlaceableImage
The logo object, not nullable.
Remarks
The reference point for the placement of the logo is (MarginLeft / Page.Height). The default coordinates of the logo relative to the reference point are (ContentWidth / -15 mm), alignment Right / Top, i.e. the logo will be placed right-aligned to the right margin.
- See Also
MarginLeft
Gets or sets the left margin of the report in points. The default value is 15 millimeters.
public double MarginLeft { get; set; }
Property Value
- double
The left margin in points.
- See Also
MarginLeftMM
Gets or sets the left margin of the report in millimeters. The default value is 15 millimeters.
public double MarginLeftMM { get; set; }
Property Value
- double
The left margin in millimeters.
- See Also
MarginRight
Gets or sets the right margin of the report in points. The default value is 15 millimeters.
public double MarginRight { get; set; }
Property Value
- double
The right margin in points.
- See Also
MarginRightMM
Gets or sets the right margin of the report in millimeters. The default value is 15 millimeters.
public double MarginRightMM { get; set; }
Property Value
- double
The right margin in millimeters.
- See Also
Subtitle
Gets or sets the subtitle of the report.
public UserPlaceableText Subtitle { get; set; }
Property Value
- UserPlaceableText
The subtitle as a UserPlaceableText object, not nullable.
Remarks
The reference point for the placement of the subtitle is (MarginLeft / Page.Height). The default x-coordinate of the subtitle relative to the reference point is 0, alignment None, i.e. the subtitle will be placed at the left margin. The default y-coordinate of the subtitle is relative to the bottom of the Title, -5 millimeters, alignment Top, i.e. the subtitle will be placed 5 millimeters below the title. The width of the text is limited to 70% of the ContentWidth.
- See Also
TextFont
Gets or sets the text font property for the report.
The default text font property is Helvetica
, size 10.
public FontProp TextFont { get; set; }
Property Value
Title
Gets or sets the title of the report.
public UserPlaceableText Title { get; set; }
Property Value
- UserPlaceableText
The title object, not nullable.
Remarks
The reference point for the placement of the title is (MarginLeft / Page.Height). The default coordinates of the title relative to the reference point are (0 / -15 mm), alignment None / Top, i.e. the title will be placed at the left margin. The width of the text is limited to 70% of the ContentWidth.
- See Also
Methods
AddContent(RepObject, AddContentOptions)
Adds content to the report.
public void AddContent(RepObject obj, AddContentOptions options = AddContentOptions.None)
Parameters
obj
RepObjectThe object to add to the report.
options
AddContentOptionsOptions for adding the content.
Exceptions
- ArgumentNullException
The object is null.
AddStringObject(RepString, AddContentOptions)
Adds a string object to the report. CurY will be set to the next line of text.
public void AddStringObject(RepString obj, AddContentOptions options = AddContentOptions.None)
Parameters
obj
RepStringThe string object to add to the report.
options
AddContentOptionsOptions for adding the content.
Exceptions
- ArgumentNullException
The object is null.
AddTable(TableLayoutManager)
Adds a table to the report, automatically managing page breaks and content flow.
public void AddTable(TableLayoutManager tlm)
Parameters
tlm
TableLayoutManagerThe table layout manager controlling the table's appearance and content.
Exceptions
- ArgumentNullException
The table layout manager is null.
- See Also
CreateEnd()
Creates the user placeable text objects that contain the variable NumberOfPages. This method is called at the end of the report creation process as the value is not known until then.
protected override void CreateEnd()
CreateNewPage()
Creates a new page with a header and footer.
public void CreateNewPage()
Remarks
This method creates a new page, adds it to the report, and creates the header and footer.
An exception is the first call to CreateNewPage().
The constructor creates the first page without content and assigns it to the variable CurPage.
On the first call to CreateNewPage(), this page is added to the report and the header and footer are then created.
After the new page has been created and before the header is created, the PreparePage() method is called, which can be overridden.
The header objects are created in the following order:
- Logo
- CompanyName
- Title
- Subtitle
- Comment
- Description
- Footnote
- FooterLeft
- FooterCenter
- FooterRight
<NumberOfPages>
, this text object is only created after the entire report is finished.
After the footer has been created, the FinalizeFooter() method is called, which can be overridden.
If there are report objects that should be kept together (i.e., added with AddContent(RepObject, AddContentOptions) parameter keepWithNext
= true), these are now placed on the page.
CreateNewPage(PageSize, PageOrientation)
Creates a new page with the specified page size, orientation, header and footer.
public void CreateNewPage(PageSize pageSize, PageOrientation pageOrientation)
Parameters
pageSize
PageSizeThe size of the page.
pageOrientation
PageOrientationThe orientation of the page.
- See Also
CreateStart()
Creates the header and footer for the first page of the report. This method is called at the beginning of the report creation process.
protected override void CreateStart()
FinalizeFooter()
After the footer has been created, the FinalizeFooter() method is called, which can be overridden.
protected virtual void FinalizeFooter()
Flush()
Flushes all queued objects that must be kept together.
public void Flush()
PreparePage()
After a new page has been created and before the header is created, the PreparePage() method is called, which can be overridden.
protected virtual void PreparePage()
SetMinimalHeader()
Sets the header to a minimal design with only the title and subtitle.
public void SetMinimalHeader()
- See Also