0
votes

In MigraDoc, I know I can add a page count reference to the document using AddNumPagesField, but is it possible to determine if there are multiple pages?

The methods AddPageField and AddNumPagesField do not contain any useful information.

Basically, I want to do something like:

if(/* document has multiple pages*/) {
    //do something here
}
1

1 Answers

1
votes

With MigraDoc, pages do not exist until a document is rendered.

MigraDoc does not create any pages when rendering to an RTF file. Pages do not exist there.

MigraDoc creates pages when rendering to PDF.

AddPageField and AddNumPagesField are placeholders. They remain placeholders when rendering to RTF, they will be replaced by the real values when creating PDF - their values cannot be determined while the MigraDoc document is still being created.

What you can do: Assume the most likely case (e.g. multiple pages) and create the document. If it only has a single page, then discard it and create it again for the single-page case.

Or maybe use PDFsharp to modify the PDF file created by MigraDoc as needed, now adding the contents that depend on the page count.