Hello,
What I ended up doing was exactly that,
I prepare the documento check the current number of pages, and remove the elements on the cell that has the pagination (looping through the objects in the primary footer).
I find the cell by using the Tag property.
So what I did, step by step, in case someone needs it is:
1- Start generating the pdf;
2- When I need to make the footer (where I have my pagination), I add a Tag with a string "draws_pagination_if_one_page" to the cell that contains pagination (Since I use tables in the footer).
3- Generate the rest of the pdf.
4- Before rendering and saving it, I use the PrepareDocument() method like this:
Code:
// mDocument is my MigraDoc document
DocumentRenderer _renderer = new DocumentRenderer(mDocument);
_renderer.PrepareDocument();
this way I can get the page count like this:
Code:
int pageCount = _renderer.FormattedDocument.PageCount;
5- since I have the page count and the document is not rendered I can still make changes to it.
So I loop through the ((Section)mDocument.Sections.First).Footers.Primary.Elements.
until I find the Cell where
Code:
Tag?.ToString() == "draws_pagination_if_one_page"
if exists
6- After and if I find the cell I just do
Code:
// Note that here I'm doing it on the first section's Footer, since thats the only footer configuration I use,
// if you use other types of footers you'll need to adjust the solution for your needs
((Table)((Section)mDocument.Sections.First).Footers.Primary.Elements[i]).Rows[j].Cells[l].Elements.Clear();
7- Then I just render and save the document.
The way that Thomas adviced, this is, adding the pagination during the render on the for loop will be more performant, but this, at least for my needs, is enough.