Hello,
I use Aspose.Word 2.4.1 with Java and i have problem to import Header/Footer node from a document to another . I’m seaching for a example but i didn’t find any samples…
I have always this error : “Cannot insert a node of this type at this location.”
My code is :
/**
* Method to add a header or a footer to a document
*
* @param document
* Source document
* @param section
* Section source containing Header/Footer
* @param headerFooterType
* Type used to specify if the content added is a HEADER or a
* FOOTER section (use object "com.aspose.words.HeaderFooterType"
* constants to specify the value)
* @return the updated document
* @throws Exception
* @see com.aspose.words.HeaderFooterType
*/
public static Document addHeaderFooter(Document document, Section section,
int headerFooterType) throws Exception {
// Check document input parameter
if (document == null) {
throw new IllegalArgumentException(
"Document object can’t be null !");
}
if (section == null) {
throw new IllegalArgumentException(
"the section object can’t be null !");
}
// Create a builder to modify document
DocumentBuilder documentBuilder = new DocumentBuilder(document);
// Move to the HEADER or FOOTER section
documentBuilder.moveToHeaderFooter(headerFooterType);
// Add content to the document
for (int i = 0; i < section.getHeadersFooters().getCount(); i++) {
Node node = document.importNode(section.getHeadersFooters().get(i),
true, ImportFormatMode.KEEP_SOURCE_FORMATTING);
documentBuilder.getCurrentSection().getHeadersFooters().add(node);
}
return document;
}
Thanks in advance for your help
Dominique