Linq Reporting - Reset header, footer and page number for each record


The idea is to use Linq reporting to create invoices.
Each invoice starts on a new page.
The invoice is kind of a master detail form and it may span across multiple pages.

Something like this:

<<foreach [i in ds.invoices]>>
    Number: <<[i.number]>>
    Account: <<[i.account]>>
    [invoice body including table with line items]

Since a single invoice may span across multiple pages the word template has different header and footer for the first page. It also has page number in the footer.

You are probably already guessing what is happening.
If the data set has a single invoice it is fine. If it has multiple invoices then the page number will be sequential and the “first page” header will be literally in the first page of the document containing all the invoices.

So the question is: is there a way to reset it on each record (header, footer and page number)? Or maybe create each document individually and some how merge them together since at the end all i need is actually a single pdf document as the output?



To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document.
  • Please attach the output Word file that shows the undesired behavior.
  • Please attach the expected output Word file that shows the desired behavior.
  • 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 will start investigation into your issue and provide you more information. Thanks for your cooperation.

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


I put together a template and project that can be used to illustrate what is described on my first post. (101.1 KB)



You are using different header and footer for the first page. The HeaderFooter is a section-level node and can only be a child of Section. There can only be one HeaderFooter or each HeaderFooterType in a Section.

In your case, we suggest you following solution.

  1. Clone the header and footer of template document.
  2. After generating the report using LINQ Reporting, replace the page break with section break.
  3. Copy the content of clone header and footer to each section.

You may generate one document per invoice and then merge all generated document. Hope this helps you.


Thanks, the first approach - replace page breaks with section break - may not work well since a template may contain page break inserted by the user who created it (when creating a multi-page template) and not only those added when processing each data row.

As for generating one document per invoice.
How would that impact performance? Instantiating a “Document” object and reading the template again for each record… are there some best practices to keep it optimized?

And one last questions: If I merge all generated documents. At the end I will have a single word document with a couple hundred pages. Isn’t the same issue with continuous header, footer page numbers going to happen again?



Yes, this may cause performance issue. When you create huge number of documents, you will face the performance issue.

Please manually create your expected Word document using Microsoft Word and attach it here for our reference. We will investigate how you want your final Word output be generated like. We will then provide you more information about your query.