Image can't be displayed after merging word pages

We are splitting all word pages then we find keyword in each page and replace it with image. After that we merge each page by Apache POI, there is two scenarios

  1. While merging two pages, if first one contains any image and we merge it with second page which have find and replaced image. It will work perfectly.
  2. But, 1st page does not contains any image and we merge it with replaced image second page it is showing me “image can’t be displayed”.

#2 is my problem, I will explain it more if you need anything.

@bhawanisingh.shekhawat it looks like Apache POI issue. Why don’t you use Aspose.Words to merge pages back into one document? You can use Document.extractPages method to split document page by page and then use Document.appendDocument method to merge them back into one document. Also, in the latest version you can use use Merger class to merge documents

Yes, we are using apache poi lib for merging two document. but when we are using aspose to merge two document it show half empty page in result document like:
aspose-merged-output.docx (15.8 KB)
but my required output should be like.
my-required-merged-output.docx (15.5 KB)

input file 1: Document1.docx (14.5 KB)
input file 2: Document2.docx (14.8 KB)

@bhawanisingh.shekhawat You can use the following code to get the required output using Aspose.Words:

Document doc1 = new Document("C:\\Temp\\Document1.docx");
Document doc2 = new Document("C:\\Temp\\Document2.docx");

// Remove redundant empty paragraphs from the end of the documents.
while (!doc1.getLastSection().getBody().getLastParagraph().hasChildNodes())
    doc1.getLastSection().getBody().getLastParagraph().remove();
while (!doc2.getLastSection().getBody().getLastParagraph().hasChildNodes())
    doc2.getLastSection().getBody().getLastParagraph().remove();

// Specify section start for the first section of the second document to continuous
// to avoid page break
doc2.getFirstSection().getPageSetup().setSectionStart(SectionStart.CONTINUOUS);

// Merge documents.
doc1.appendDocument(doc2, ImportFormatMode.KEEP_SOURCE_FORMATTING);

doc1.save("C:\\Temp\\out.docx");