I use the OpenXML SDK v2.11.3 with .net core 3.1 and when I try to get the total pages count from a word document sometimes it returns a null value.
using (var document = WordprocessingDocument.Open(memoryStream, true))
{
var pages = Convert.ToInt32(document.ExtendedFilePropertiesPart.Properties.Pages.Text);
}
System.NullReferenceException: 'Object reference not set to an instance of an object.' DocumentFormat.OpenXml.ExtendedProperties.Properties.Pages.get returned null.
What is the best way to get the total pages count from a docx file ?
Since
you cannot necessarily obtain a page count from an arbitrary DOCX file.
For further details and some limited work-arounds, see How to access OpenXML content by page number?