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

Free Support Forum - aspose.com

Formatting issues in the generated docx after merging two documents

Hi,

We combine 2 different documents(891222_FP.docx,891222_UM.docx) into a single docx using Aspose.

In the generated docx(891222_SU_KPM_windnewjar.docx), we see the table format/style in page 4 and 5 is different than the one from the input <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /> 891222_UM.docx when we use ImportFormatMode.USE_DESTINATION_STYLES.

When we use ImportFormatMode.KEEP_SOURCE_FORMATTING there are extra blank lines in generated docx 891222_SU_KPM_keepsourceformat.docx page 4 to 7.

We are using the Aspose words 10.6.0 jar.

Here is the code snippet we use to create document.

ByteArrayInputStream fpByteStream = null;

fpByteStream = new ByteArrayInputStream(byteArray);

doc = new Document(fpByteStream);

After that, we merge the documents using

Document FP, Document LAS, Document UM;

UM.getFirstSection().getPageSetup().setSectionStart(SectionStart.NEW_PAGE);

UM.getFirstSection().getPageSetup().setDifferentFirstPageHeaderFooter(false);

UM.getFirstSection().getHeadersFooters().linkToPrevious(true);

FP.appendDocument(UM, ImportFormatMode.USE_DESTINATION_STYLES);

(or)

FP.appendDocument(UM, ImportFormatMode.KEEP_SOURCE_FORMATTING );

Hi

Thanks for your request. Please try using the following code:

Document FP = new Document("C:\\Temp\\891222_FP.docx");

Document UM = new Document("C:\\Temp\\891222_UM.docx");

UM.expandTableStylesToDirectFormatting();

UM.getFirstSection().getPageSetup().setSectionStart(SectionStart.NEW_PAGE);

UM.getFirstSection().getPageSetup().setDifferentFirstPageHeaderFooter(false);

UM.getFirstSection().getHeadersFooters().linkToPrevious(true);

FP.appendDocument(UM, ImportFormatMode.USE_DESTINATION_STYLES);

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

Hope this helps.

Best regards,