code is following.
int docPageCount = oriDoc.PageCount;
for (int index = 0; index < docPageCount; index++)
{
Document page = oriDoc.ExtractPages(index, 1);
PageInfo pageInfo = page.GetPageInfo(0);
bool isLandscape = pageInfo.Landscape;
if (!isLandscape)
{
foreach (Section section in page.Sections)
{
foreach (HeaderFooter headerFooter in section.HeadersFooters)
{
foreach (Node node in headerFooter.GetChildNodes(NodeType.Shape, true))
{
Shape shape = (Shape)node;
if (shape.HasImage)
{
shape.Remove();
}
}
}
}
}
string tempOutput = tempFolderName + Path.DirectorySeparatorChar + oriDoc.GetHashCode() + "_page" +
index +
".docx";
page.Save(tempOutput, SaveFormat.Docx);
The original file has a page count of 17, but after importing it as a Document object using Aspose, the PageCount property returns 23. Furthermore, the exported file also has a page count of 23, and the formatting of the header and tables is incorrect.
the input file:input (2).docx (89.6 KB)
the output file:24724999_withLogo.docx (71.8 KB)