Designing Sales Delivery Notes with Blank Row Filling Using FastReport: A Guide with A4 Template
This guide demonstrates how to design a sales delivery note print template that automatically fills blank rows to maintain a consistent table height on each page, using the FastReport designer.
Overview of the Blank Row Filling Template
Template Preview:
We will use a Sales Delivery Note as an example.
Step-by-Step Configuration
1. Identify the Document ID
Create a new Sales Delivery Note in your system.
Return to the list view and edit the newly created document.
Note the document ID displayed at the top of the form.
2. Duplicate and Prepare the Print Template
Navigate to Configuration > Report Templates.
Find the sales delivery note print template you wish to modify.
Duplicate the template and open the duplicate for editing.
In the template details, locate the data parameter settings and note the current ID parameter (you will update this later).
3. Launch the Report Designer
Ensure the FastReport service is running.
From the report template list, click "Design Template" for your duplicated template.
4. Initial Designer View
Upon entering, you will see the default template layout.
5. Reorganize Report Bands
5.1. Add Necessary Bands
Click the Settings (gear icon) in the top-left corner.
Add a Page Header band and a second Data band.
The interface after adding bands:
5.2. Move Content and Clean Up
Move the content from the "Report Title" band and the first row from the original "Data" band in to the new Page Header band.
Delete the now-empty "Report Title" and the original "Data Header" bands.
5.3. Identify Data Bands
You will now have two main data bands:
The upper band (Data1) will contain the actual transaction lines.
The lower band (Data2) will be used for filling blank rows. Click on the yellow area of each band to see its name selected in the Report Tree on the right.
5.4. Configure the Blank Row Band (Data2)
Copy the table structure (cells, borders) from Data1 and paste it into Data2.
Clear all data bindings and text from the cells in Data2. This band should contain only the empty table structure.
5.5. Move Foooter Content
Move the content from the "Report Summary" band (like totals) into the Page Footer band.
Delete the empty "Report Summary" band.
6. Add the Automation Script
Switch to the Code view by clicking the button at the bottom-left of the designer.
The default code structure will be visible.
6.1. Insert the Custom Code
Add the following code block inside the ReportScript class. The exact line may vary, but it should be placed with other event hendlers.
// --- BEGIN INSERTED CODE ---
int maxRowsPerPage = 16; // Maximum data rows to display per page
private void Page1_StartPage(object sender, EventArgs e)
{
int actualDataRowCount = Data1.DataSource.RowCount;
int blankRowsNeeded = maxRowsPerPage - (actualDataRowCount % maxRowsPerPage);
// If the data exactly fills the page, hide the blank row band.
if (blankRowsNeeded == maxRowsPerPage)
{
Data2.Visible = false;
}
else
{
Data2.Visible = true;
Data2.RowCount = blankRowsNeeded; // Set the number of blank rows to render
}
}
// --- END INSERTED CODE ---Complete ReportScript class example after insertion:
namespace FastReport
{
public class ReportScript
{
int maxRowsPerPage = 16;
private void Page1_StartPage(object sender, EventArgs e)
{
int actualDataRowCount = Data1.DataSource.RowCount;
int blankRowsNeeded = maxRowsPerPage - (actualDataRowCount % maxRowsPerPage);
if (blankRowsNeeded == maxRowsPerPage)
{
Data2.Visible = false;
}
else
{
Data2.Visible = true;
Data2.RowCount = blankRowsNeeded;
}
}
// ... other existing code ...
}
}6.2. Code Explanation & Customization
Data1: Refers to the band containing your actual sales items.Data2: Refers to the band that will generate the empty rows.maxRowsPerPage = 16: This variable defines how many data rows (excluding headers) fit on a single page. You must adjust this number based on your page size (e.g., A4, Letter) and font size.
7. Bind the Event Handler
Switch back to the Design view.
In the Report Tree, select the top-level Page1.
In the Properties pane, click the Events tab (lightning bolt icon).
Find the
StartPageevent, click the dropdown, and selectPage1_StartPage(the method you just created).
8. Preview and Finalize
Click Preview (or Report > Preview) to test the template.
The
Data2band should now generate enough empty rows to make the total rows on each page equal tomaxRowsPerPage.
Important Note on maxRowsPerPage: This number represents the total body rows per page. For an A4 sheet with your specific layout, this might be 44 rows, not 16. Determine the correct value by checking how many rows of your Data1 table fit on a single page in the preview.
9. Update the Template Data Parameter
Before using the template in your system, you must finalize its configuration.
Save and exit the report designer.
Back in your system's report template configuration, edit the details of your new template.
Find the data parameter (often named "ID" or similar) that was initially set to a specific document ID.
Change this parameter's value to
0(zero). This typically makes the template generic, allowing it to be used for any document by passing the correct ID at print time.
Download Ready-to-Use Templates
Two pre-configured sales delivery note templates with blank row filling are provided for download:
One formatted for a page size fitting 16 rows.
One formatted for A4 paper.