Context of the issue
I recently needed to add a very long text (about half of page with Terms and Conditions of Sale) only on the last page of a RDLC Invoice Document (using Visual Studio Report Designer to create report documents for NAV). The last page had to contain only this text and not interfere with the other pages.
The Invoice needed to have headers on each page (Invoice No, Date etc), so in order for the header to be printed correctly on every page when printing multiple invoices at same time, I had to use the SetData / GetData method:
This is needed because in the Header of a RDLC report you can add information from the body of the report only by using a formula like for example First(field) or Last(field). This means that in case of printing multiple documents in same file, all invoices would have the same header if we don’t use the SetData / GetData method.
Problem with last page with a long text in RDLC report
My first idea to add the long text on the last page of the report was to create at the end of the report (within the main Rectangle) a Rectangle with a TextBox in it that would contain all that long text. Then, in order to print this Rectangle on a new Page (last page), I tried to add a Page Break before this new Rectangle. Unfortunately, this approach does not work properly: because of the page break, the information from the headers is messed up when printing multiple different documents in same time. I don’t have an explanation for this, it looks like the combination SetData / GetData and Page Breaks gives wrong results: when printing the header of the page after the page break, it sometimes gets information from another record instead of from the correct record..
A way to solve the issue
Printing the long text on a new page at the end of the Invoice, can be accomplished like this:
- At the end of Report (within the main Rectangle), add the new Rectangle with the TextBox in it. Then add the needed text in the TextBox
- Measure the height of Page: go to Report Properties and check the ‘Height’ property (in my case for example it was 29.7cm)
- Subtract the Top and Bottom margins (in my case it was 29.7cm – 1.4cm = 28.3 cm)
- Measure the height of the Page Header and subtract the value from the above result (28.3cm – 4.74cm = 23.5 cm)
- Go to the newly created Rectangle’s properties and in the Size, set the Height to 23.5cm (the result of above subtractions). Now the Rectangle occupies a whole page.
- Set the property KeepTogether on the Rectangle to TRUE.
In this way everything that is inside the rectangle is added on a new last page of the report. This is because even if there are only few items in the previous page, it would still not have enough space to print on that one, so it needs to go to a new page 🙂
It took some time and stress to figure this out, so I hope it helps!