Body.removeAllChildren "removes" header

@jkrauseno

Further to my previous post, the EditableRangeStart class represents a start of an editable range in a Word document. EditableRangeEnd class represents an end of an editable range in a Word document.

A complete editable range in a Word document consists of a EditableRangeStart and a matching EditableRangeEnd with the same Id. EditableRangeStart and EditableRangeEnd are just markers inside a document that specify where the editable range starts and ends.

As a workaround of this issue, you can use the following code snippet to get the desired output.

System.out.println("Number of headers after removeAllChildren: " + newDocument.getFirstSection().getHeadersFooters().getCount());
doc.getFirstSection().getPageSetup().setSectionStart(SectionStart.CONTINUOUS);
newDocument.appendDocument(doc, ImportFormatMode.KEEP_SOURCE_FORMATTING);
newDocument.getSections().get(1).getHeadersFooters().linkToPrevious(true);

// code to workaround this issue start
newDocument.protect(ProtectionType.READ_ONLY);

DocumentBuilder builder = new DocumentBuilder(newDocument);
builder.moveToDocumentStart();
builder.startEditableRange();
builder.moveToDocumentEnd();
builder.endEditableRange();
// code to workaround this issue end

newDocument.save(MyDir + "output.docx", com.aspose.words.SaveFormat.DOCX);

Thanks a ton. Workaround does the trick, brilliant. My manager will now enter the process of purchasing the adequate license for our customer :slightly_smiling_face:

BR