@awais.hafeez
Here is the code we implemented on our side. Do you know what would be wrong with this code?
this.moveToSection(1);
Section currentSection = this.getCurrentSection();
while (currentSection != null) {
Section previousSection = (Section) currentSection.getPreviousSibling();
if (currentSection.getPageSetup().getOrientation() != previousSection.getPageSetup().getOrientation()) {
Section previousHeaderSection = previousSection;
HeaderFooter previousHeader = null;
while (previousHeader == null && previousHeaderSection != null) {
previousHeader = previousHeaderSection.getHeadersFooters().getByHeaderFooterType(HeaderFooterType.HEADER_PRIMARY);
previousHeaderSection = (Section) previousHeaderSection.getPreviousSibling();
}
Section previousFooterSection = previousSection;
HeaderFooter previousFooter = null;
while (previousFooter == null && previousFooterSection != null) {
previousFooter = previousFooterSection.getHeadersFooters().getByHeaderFooterType(HeaderFooterType.FOOTER_PRIMARY);
previousFooterSection = (Section) previousFooterSection.getPreviousSibling();
}
currentSection.getHeadersFooters().linkToPrevious(false);
currentSection.getHeadersFooters().clear();
if (previousHeader != null) {
currentSection.getHeadersFooters().add(previousHeader.deepClone(true));
}
if (previousFooter != null) {
currentSection.getHeadersFooters().add(previousFooter.deepClone(true));
}
for (HeaderFooter headerFooter : currentSection.getHeadersFooters()) {
// Resize tables width to use all available space
TableCollection tables = headerFooter.getTables();
for (com.aspose.words.Table table : tables) {
table.setPreferredWidth(PreferredWidth.fromPercent(100));
table.setAlignment(TableAlignment.CENTER);
}
// Resize width of lines to use all available space
NodeCollection<Shape> shapes = headerFooter.getChildNodes(NodeType.SHAPE, true);
for (Shape shape : shapes) {
if (ShapeType.LINE == shape.getShapeType() || shape.isHorizontalRule() || shape.isSignatureLine()) {
shape.setWidth(
currentSection.getPageSetup().getPageWidth() - currentSection.getPageSetup().getLeftMargin()
- currentSection.getPageSetup().getRightMargin());
shape.setHorizontalAlignment(HorizontalAlignment.LEFT);
shape.setRelativeHorizontalPosition(RelativeHorizontalPosition.MARGIN);
}
}
}
}
currentSection = (Section) currentSection.getNextSibling();
}