We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Document Later Template example

Looking for another example of merging a document into a document letter head that contains just Header and Footers.

When merging the second document I want to get the content only from the second document no headers and footers and merge into the letter head and if there are multiple pages all pages contain the header and footer.



Thanks for your inquiry. You can try using the following code:

Document doc1 = new Document(getMyDir() + “headers.doc”);
Document doc2 = new Document(getMyDir() + “body.doc”);

for(Section sec : doc2.getSections()){
NodeCollection nodes = sec.getBody().getChildNodes(NodeType.ANY, false);
for(Node node : (Iterable) nodes){
doc1.importNode(node, true, ImportFormatMode.KEEP_SOURCE_FORMATTING));

doc1.save(getMyDir() + “awjava-16.3.0.docx”);

Hope, this helps.

In case you face any problems, please attach your input Word documents and expected final document here for our reference. We will investigate the structure of your expected document as to how you want your final output be generated like. You can create expected document using Microsoft Word. We will then provide you code to achieve the same using Aspose.Words.

Best regards,