Isert editable Rtf document in the docx document

Hi Sreelakshmi,

Thanks for your patience and sorry for the delayed response. Could you please run the following code on your side and let us know if it produces the desired output.

Document mainDoc = new Document("c:\test\template.docx");

Document subDoc = new Document("c:\test\Output.rtf");
NodeCollection paras = mainDoc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true);

Paragraph startPara = null;

Paragraph endPara = (Paragraph)paras.get(paras.getCount() - 1);

for (Paragraph p : (Iterable<Paragraph>
    )paras)
{

    if (p.getRange().getText().contains("{Output}"))
    {

        startPara = p;

        break;

    }

}

ArrayList beforeKeyword = extractContent(paras.get(0), startPara, true);

ArrayList afterKeyword = extractContent(startPara, endPara, true);

Document beforeKeywordDoc = generateDocument(mainDoc, beforeKeyword);

Document afterKeywordDoc = generateDocument(mainDoc, afterKeyword);

beforeKeywordDoc = addHeaderFooter(beforeKeywordDoc, mainDoc.getFirstSection(), HeaderFooterType.HEADER_PRIMARY);

afterKeywordDoc = addHeaderFooter(afterKeywordDoc, mainDoc.getFirstSection(), HeaderFooterType.HEADER_PRIMARY);

Document finalDoc = new Document();

finalDoc.removeAllChildren();

finalDoc.appendDocument(beforeKeywordDoc, ImportFormatMode.KEEP_SOURCE_FORMATTING);

finalDoc.appendDocument(subDoc, ImportFormatMode.KEEP_SOURCE_FORMATTING);

afterKeywordDoc.getFirstSection().getHeadersFooters().linkToPrevious(false);

afterKeywordDoc.getFirstSection().getPageSetup().setSectionStart(SectionStart.CONTINUOUS);

finalDoc.appendDocument(afterKeywordDoc, ImportFormatMode.KEEP_SOURCE_FORMATTING);

// Before saving remove {Output}

Node[] nodes = finalDoc.getChildNodes(NodeType.PARAGRAPH, true).toArray();

for (Node n : nodes)
{

    if (n.getRange().getText().contains("{Output}"))
    {

        n.remove();

    }

}

for (Section s : finalDoc.getSections())
{

    s.getPageSetup().setOrientation(Orientation.LANDSCAPE);

}

finalDoc.save("c:\test\outJAVA.docx");

I hope, this will help.

Best Regards,

Hi I am using the aspose.words.jar file which was released on march 2010.
In the final output file the template headers are not merging withe the Editable rtf headers.
I want he final output file having the main document headers and footers for the before key word and after key word and sub document should append with the headers or the main document(header of the page containing key word).
refer 7,8,9th pages in attached document.
Please find the attached sample output file.

Hi Sreelakshmi,

Thank you for providing the additional information and your patience. We are working over you query and please expect a reply within next 24 hours.

Best Regards,

Hi
Sreelakshmi,

Thanks for your patience. I have attached the code here (please see Final code.txt) for your reference. Please let me know if I can be of any further assistance.

Best Regards,

Hi Hafeez,
Where can I find code for the method ‘addHeaderFooter’. I am getting the exception when I integrate the attached code.

beforeKeywordDoc = addHeaderFooter(beforeKeywordDoc, maindoc.getFirstSection(), HeaderFooterType.HEADER_PRIMARY);
afterKeywordDoc = addHeaderFooter(afterKeywordDoc, maindoc.getFirstSection(), HeaderFooterType.HEADER_PRIMARY);

Thanks,

I can see the code. Ignore previous post.
Thanks

Thanks it works, the headers are merging. I have some other issues that i am going to track under the below thread.
https://forum.aspose.com/t/exception-while-using-crimson-1-1-3-jar-with-aspose-words-for-java/55084/10
Thanks,

Hi
Sreelakshmi,

Thanks for your feedback. It is perfect that you managed to merge headers on your side. Please let us know any time you have any further queries. Regarding your other issue, I would suggest you please follow this thread for further proceedings.

Best Regards,

HI,
I need to use paragraphFormat.setSpaceAfter(),paragraphFormat.setSpaceBefore() in the header part.
can you please suggest me how to set spaceAfter,spacebefore in the header part?
Regards
Sreelakshmi.

Hi Sreelakshmi,

Thanks for your inquiry.

Well, please get a reference to a Paragraph node in your header and set the amount of spacing before/after that Paragraph by using ParagraphFormat.SpaceAfter and ParagraphFormat.SpaceBefore properties. I would suggest you please read the Paragraph Formatting section in the following article:
https://docs.aspose.com/words/java/programming-with-documents/

I hope, this helps.

Best regards,