Resize Word document and reflow the contents

I’m trying to change the page size of Word documents and have the corresponding content reflow. Most recently I’ve tried the following code:

var document = new WordDocument(pathToDoc);

foreach (var section in document.Sections.Cast<Section>())
{
    section.PageSetup.PageHeight = newHeight;
}

Unfortunately, when shrinking the page height of the sections, the document isn’t reflowing correctly and the contents start to overlap and become unreadable. The curious thing I noticed is that for a document with 4 pages, there were 7 sections. I was under the impression that each page was a “section” of the document. Is that not correct? We’re trying to programmatically reduce the height of Word documents that are submitted to account for a header in the printout. Any help here would be greatly appreciated.

@bhasden,

Thanks for your inquiry. To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document.
  • Please attach the output Word file that shows the undesired behavior.
  • Please attach the expected output Word file that shows the desired behavior.
  • Please create a standalone console application (source code without compilation errors) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.