package com.aspose.words.examples.programming_documents.joining_appending; import com.aspose.words.Document; import com.aspose.words.ImportFormatMode; import com.aspose.words.SectionStart; import com.aspose.words.examples.Utils; public class LinkHeadersFooters { public static void main(String[] args) throws Exception { // The path to the documents directory. String dataDir = Utils.getDataDir(LinkHeadersFooters.class); Document dstDoc = new Document(dataDir + "TestFile.Destination.doc"); Document srcDoc = new Document(dataDir + "TestFile.Source.doc"); // Set the appended document to appear on a new page. srcDoc.getFirstSection().getPageSetup().setSectionStart(SectionStart.NEW_PAGE); // Link the headers and footers in the source document to the previous section. // This will override any headers or footers already found in the source document. srcDoc.getFirstSection().getHeadersFooters().linkToPrevious(true); dstDoc.appendDocument(srcDoc, ImportFormatMode.KEEP_SOURCE_FORMATTING); dstDoc.save(dataDir + "output.doc"); } }