Reputation: 12317
We have an application that reads Word documents and imports them into our file format.
A recent bug was found that the page count is only available in Page Layout View, however Word 2010 defaults to Web Layout.
Using .NET c# how can we change the view to give us back the page count?
Upvotes: 4
Views: 3476
Reputation: 1
//Here is my code snipped based on 'DocumentFormat.OpenXml' nuget package.
//Open doc file
using (var wordDocument = WordprocessingDocument.Open(strInputFile,true))
{
SectionProperties sectionProps = new SectionProperties();
//Set page margins
PageMargin margin = new PageMargin() { Top = 1008,
Right = (UInt32Value)1008U,
Bottom = 1008,
Left = (UInt32Value)1008U,
Header = (UInt32Value)720U,
Footer = (UInt32Value)720U, `enter code here`
Gutter = (UInt32Value)0U };
sectionProps.Append(margin);
//Apply margin
wordDocument.MainDocumentPart.Document.Body.Append(sectionProps);
//Save changes
wordDocument.Save();
}
Upvotes: 0