How to get current page number in Word template, using LINQ Reporting Engine tag

Hi,

I know there are lots of tags in LINQ Reporting Engine, such as

<<if []>><<elseif []>><<else>><</if>>
<<foreach>><</foreach>>
<<[ControlChar.PageBreak]>>

But how to get the current page number?
I tried something like, but no luck

<<[Document.PageCount]>>
<<[doc.PageCount]>>

Could you please let me know the correct tag?

Regards,
Zhenyu

@zhenyu.wang There is no such tag, because as you may know MS Word documents are flow by their nature and do not have “Page” concept. The consumer applications, like MS Word, reflows the document content into page on the fly. So to insert page numbed into the document you should use standard PAGE field.

But I would like to insert a page break, if the last page is NOT an even number page.

I tried this and did not work.
<<if [page nubmer from Word % 2 != 0]>><<[ControlChar.PageBreak]>><</if>>

The OOTB Word ‘section break’ adds 2 extra blank pages, if the last page is an even number page

@zhenyu.wang I am afraid there is no way to achieve this using LINQ Reporting syntax. But you can achieve this by postprocessing the document in the code:

Document doc = new Document(@"C:\Temp\in.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
if (doc.PageCount % 2 > 0)
{
    builder.MoveToDocumentEnd();
    builder.InsertBreak(BreakType.PageBreak);
}
doc.Save(@"C:\Temp\out.docx");