How to get MS Word total pages count using Open XML SDK?

前端 未结 2 951
余生分开走
余生分开走 2021-01-19 07:50

I am using below code to get the page count but it is not giving actual page count(PFA). What is the better way to get the total pages count?

var pageCount =         


        
2条回答
  •  旧时难觅i
    2021-01-19 08:43

    This code worked for me. It adds "Page X of Y" to the document.

    para = new Paragraph(new Run(
           new Text() { Text = "Page ", Space = SpaceProcessingModeValues.Preserve },
           new SimpleField() { Instruction = "PAGE" }, 
           new Text() { Text = " of ", Space = SpaceProcessingModeValues.Preserve },  
           new SimpleField() { Instruction = "NUMPAGES \\*MERGEFORMAT" }));
    

提交回复
热议问题