Free Support Forum -

Realizing a table with a special footer and header row upon every page break

Hello dear support team,

I’m currently working on generating PDF invoices from a *.docx template in .NET.
The main part of the invoice is a table with a variable number of rows, depending on how much items the customer bought (every row contains an item).
One special case currently gives me headaches: When invoices are longer than one page (which means they include one or more page breaks), I need a special row at the end of the “old” page and a special row at the beginning of the next page. The link leads to an example PDF to show what I mean (the special rows are the rows “Zwischensumme” and “Übertrag”). I deleted all company-related data, but I think the problem
should be clear nonetheless.
InvoiceExample_empty.pdf (271.6 KB)

I found a very hacky solution to the problem: First, I build the invoice including the table with the ReportingEngine. Then, I iterate through the table rows and for every row I check, if LayoutCollector.GetStartPage is bigger than the startpage of the previous row. If this is the case, I insert the special rows and some empty rows until “Übertrag” moves to the top of the next page.
The problem is that I have to call LayoutCollector.GetStartPage for every single row to find the point where the page breaks which eats up so much performance that the generation of a PDF with 4 pages takes up to 10 seconds.

My web research suggests that this function (with the special footer and header rows) is not supported in MS Word, so I don’t have high hopes that there is an elegant solution with Aspose.Words, but I didn’t want to miss the opportunity to ask.

If you need any more information from me, please let me know.
Thanks in advance!


Thanks for your inquiry. Please note that Aspose.Words mimics the behavior of MS Word. Your solution for this scenario is correct. Regarding the performance issue, please attach the following resources here for testing:

  • Your input Word document.
  • Please create a standalone console application (source code without compilation errors) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we’ll start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.


Thanks for the fast response. I prepared a console application which hopefully matches your requirements and enables you to reproduce the problem. (6.2 MB)
I uninstalled the Aspose.Words nuget package before uploading due to its size, so to get the application running, you would have to reinstall the package (I used version 18.1.0) and add a license file to the folder “AsposeLicense”.
The *.docx template can be found in the folder “InvoiceGenerationExample”.

I hope that my provided files are sufficient, but if something is not working, please let me know.
Thanks in advance!


Thanks for sharing the detail. We are investigating this issue and will get back to you as soon as possible.


You are creating object of LayoutCollector class 80 times. This causes the performance issue. In your case, we suggest you please create the object before the for loop as shown below. Hope this helps you.

var layout = new LayoutCollector(invoiceDoc);
// find page breaks and add special rows "Subtotal" and "Transfer"
// for each row until "Net Total Price"
for (var i = 1; i < invoiceTable.Rows.Count - 3; i++)


Thank you! It’s a lot faster now. I don’t even know how the object declaration ended up there, but thanks for pointing it out to me. :slight_smile:


Thanks for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.