while merging document to word, lines getting increased
One more point, i verified all compatibility versions of input document and merged document
do i need to set any compatibilities to avoid page splitting issue
For Input == getDoNotAutofitConstrainedTables:false
For Input == getDoNotBreakConstrainedForcedTable:false
For Input == getDoNotLeaveBackslashAlone:false
For Input == getDoNotSuppressParagraphBorders:false
For Input == getDoNotSuppressIndentation:false
For Input == getAutofitToFirstFixedWidthCell:false
For Input == getAllowSpaceOfSameStyleInTable:false
For Input == getDoNotUseEastAsianBreakRules:false
For Input == getBalanceSingleByteDoubleByteWidth:false
For Input == getDisableOpenTypeFontFormattingFeatures:false
For Input == getDoNotUseHTMLParagraphAutoSpacing:false
For Input == getDoNotUseIndentAsNumberingTabStop:false
For Input == getDoNotVertAlignCellWithSp:false
For Input == getPrintBodyTextBeforeHeader:false
For Input == getSelectFldWithFirstOrLastChar:false
For Input == getSuppressSpacingAtTopOfPage:false
For Input == getTruncateFontHeightsLikeWP6:false
For Input == getUseAltKinsokuLineBreakRules:false
For Input == getUseSingleBorderforContiguousCells:false
For Input == getUseWord2002TableStyleRules:false
For Input == getUseWord2010TableStyleRules:false
For Input == getAdjustLineHeightInTable:false
For Input == getAlignTablesRowByRow:false
For Input == getApplyBreakingRules:false
For Input == getAutoSpaceLikeWord95:false
For Input == getCachedColBalance:false
For Input == getConvMailMergeEsc:false
For Input == getDisplayHangulFixedWidth:false
For Input == getDoNotBreakWrappedTables:false
For Input == getDoNotExpandShiftReturn:false
For Input == getDoNotSnapToGridInCell:false
For Input == getDoNotVertAlignInTxbx:false
For Input == getDoNotWrapTextWithPunct:false
For Input == getFootnoteLayoutLikeWW8:false
For Input == getForgetLastTabAlignment:false
For Input == getGrowAutofit:false
For Input == getLayoutRawTableWidth:false
For Input == getLayoutTableRowsApart:false
For Input == getLineWrapLikeWord6:false
For Input == getMWSmallCaps:false
For Input == getNoColumnBalance:false
For Input == getNoExtraLineSpacing:false
For Input == getNoLeading:false
For Input == getNoSpaceRaiseLower:false
For Input == getNoTabHangInd:false
For Input == getPrintColBlack:false
For Input == getShapeLayoutLikeWW8:false
For Input == getShowBreaksInFrames:false
For Input == getSpaceForUL:false
For Input == getSpacingInWholePoints:false
For Input == getSplitPgBreakAndParaMark:false
For Input == getSubFontBySize:false
For Input == getSuppressBottomSpacing:false
For Input == getSuppressSpBfAfterPgBrk:false
For Input == getSuppressTopSpacing:false
For Input == getSuppressTopSpacingWP:false
For Input == getSwapBordersFacingPgs:false
For Input == getTransparentMetafiles:false
For Input == getUICompat97To2003:false
For Input == getUlTrailSpace:true
For Input == getUnderlineTabInNumList:false
For Input == getUseAnsiKerningPairs:false
For Input == getUseFELayout:false
For Input == getUseNormalStyleForList:false
For Input == getUsePrinterMetrics:false
For Input == getUseWord97LineBreakRules:false
For Input == getWPJustification:false
For Input == getWPSpaceWidth:false
For Input == getWrapTrailSpaces:false
For Input == getOverrideTableStyleFontSizeAndJustification:false
For Input == getSwapInsideAndOutsideForMirrorIndentsAndRelativePositioning:false
For Output == getDoNotAutofitConstrainedTables:true
For Output == getDoNotBreakConstrainedForcedTable:true
For Output == getDoNotLeaveBackslashAlone:false
For Output == getDoNotSuppressParagraphBorders:false
For Output == getDoNotSuppressIndentation:true
For Output == getAutofitToFirstFixedWidthCell:true
For Output == getAllowSpaceOfSameStyleInTable:true
For Output == getDoNotUseEastAsianBreakRules:false
For Output == getBalanceSingleByteDoubleByteWidth:false
For Output == getDisableOpenTypeFontFormattingFeatures:false
For Output == getDoNotUseHTMLParagraphAutoSpacing:false
For Output == getDoNotUseIndentAsNumberingTabStop:true
For Output == getDoNotVertAlignCellWithSp:true
For Output == getPrintBodyTextBeforeHeader:false
For Output == getSelectFldWithFirstOrLastChar:false
For Output == getSuppressSpacingAtTopOfPage:false
For Output == getTruncateFontHeightsLikeWP6:false
For Output == getUseAltKinsokuLineBreakRules:true
For Output == getUseSingleBorderforContiguousCells:false
For Output == getUseWord2002TableStyleRules:true
For Output == getUseWord2010TableStyleRules:false
For Output == getAdjustLineHeightInTable:false
For Output == getAlignTablesRowByRow:false
For Output == getApplyBreakingRules:false
For Output == getAutoSpaceLikeWord95:false
For Output == getCachedColBalance:true
For Output == getConvMailMergeEsc:false
For Output == getDisplayHangulFixedWidth:true
For Output == getDoNotBreakWrappedTables:false
For Output == getDoNotExpandShiftReturn:false
For Output == getDoNotSnapToGridInCell:false
For Output == getDoNotVertAlignInTxbx:true
For Output == getDoNotWrapTextWithPunct:false
For Output == getFootnoteLayoutLikeWW8:false
For Output == getForgetLastTabAlignment:false
For Output == getGrowAutofit:true
For Output == getLayoutRawTableWidth:false
For Output == getLayoutTableRowsApart:false
For Output == getLineWrapLikeWord6:false
For Output == getMWSmallCaps:false
For Output == getNoColumnBalance:false
For Output == getNoExtraLineSpacing:false
For Output == getNoLeading:false
For Output == getNoSpaceRaiseLower:false
For Output == getNoTabHangInd:false
For Output == getPrintColBlack:false
For Output == getShapeLayoutLikeWW8:false
For Output == getShowBreaksInFrames:false
For Output == getSpaceForUL:false
For Output == getSpacingInWholePoints:false
For Output == getSplitPgBreakAndParaMark:true
For Output == getSubFontBySize:false
For Output == getSuppressBottomSpacing:false
For Output == getSuppressSpBfAfterPgBrk:false
For Output == getSuppressTopSpacing:false
For Output == getSuppressTopSpacingWP:false
For Output == getSwapBordersFacingPgs:false
For Output == getTransparentMetafiles:false
For Output == getUICompat97To2003:false
For Output == getUlTrailSpace:false
For Output == getUnderlineTabInNumList:false
For Output == getUseAnsiKerningPairs:true
For Output == getUseFELayout:false
For Output == getUseNormalStyleForList:true
For Output == getUsePrinterMetrics:false
For Output == getUseWord97LineBreakRules:false
For Output == getWPJustification:false
For Output == getWPSpaceWidth:false
For Output == getWrapTrailSpaces:false
For Output == getOverrideTableStyleFontSizeAndJustification:false
For Output == getSwapInsideAndOutsideForMirrorIndentsAndRelativePositioning:false
@rbandla3 Could you please attach your input and output documents here for testing? We will check the issue and provide you more information. Unfortunately, it is impossible to analyze the problem without real documents.
@rbandla3 Do you merge the input document with an empty document created from scratch? If so it is not quite right, since document created from scratch and the source document might have different compatibility options. If your goal is concatenating several documents into one, I would suggest you to use the following code:
String[] documents = new String[] { "C:\\Temp\\Input_File1.docx", "C:\\Temp\\Input_File2.docx", "C:\\Temp\\Input_File3.docx" };
Document result = null;
for (String docPath : documents)
{
Document doc = new Document(docPath);
if (result == null)
result = doc;
else
result.appendDocument(doc, ImportFormatMode.KEEP_SOURCE_FORMATTING);
}
result.save("C:\\Temp\\out.docx");
In this case compatibility options of the first document will be used in the final document.
Yes, your right, we have to merge multiple document to single word.may i know have you noticed attached both document? where it got splitted to 2 pages that one document(input to output).
which compatibity will cause that?
Because, while merging we have to take care footers and page numbers everything so that we handled this::
ImportFormatOptions importFormatOptions = new ImportFormatOptions();
importFormatOptions.setIgnoreHeaderFooter(false);
output.appendDocument(input, ImportFormatMode.KEEP_SOURCE_FORMATTING, importFormatOptions);
@rbandla3 Unfortunately, from your previous messages it is not quite clear how you produce the problematic output document. Do you split the source document into pages and then merge them back? Could you please provide a simple code that will allow us to reproduce the problem?
@rbandla3 You should modify your code like this to get the expected output:
public byte[] mergeWordDocs(List<byte[]> wordDocs) throws DocxGenerationException {
try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
com.aspose.words.Document output = null;
for (byte[] wordFile : wordDocs) {
com.aspose.words.Document input = new com.aspose.words.Document(new ByteArrayInputStream(wordFile));
if(output == null)
{
output = input;
}
else {
input.getFirstSection().getPageSetup().setSectionStart(SectionStart.NEW_PAGE);
input.getFirstSection().getHeadersFooters().linkToPrevious(false);
input.getFirstSection().getPageSetup().setRestartPageNumbering(true);
ImportFormatOptions importFormatOptions = new ImportFormatOptions();
importFormatOptions.setIgnoreHeaderFooter(false);
output.appendDocument(input, ImportFormatMode.KEEP_SOURCE_FORMATTING, importFormatOptions);
}
}
output.save(os, SaveFormat.DOCX);
log.info("Merged all word docs for appName : {}");
return os.toByteArray();
} catch (Exception ex) {
throw new DocxGenerationException("Exception occurred while merging word docs", ex);
}
}
In your original code you are merging documents into the newly created document, which have different compatibility options than the source documents. In the code I have provided the first document in the list is used as the target document.
@alexey.noskov Thanks for your reply, above code giving same issue for again the attached files, if we are merging different words. input1.docx (31.0 KB)
@rbandla3 Your documents might be created using different version of MS Word and as a result have different set of compatibility options. When you concatenate the documents compatibility options of the main document are applied and the content is reflowed appropriately. This might lead to difference in layout of the appended documents. Unfortunately, there is no way to keep different compatibility options for different parts of the document.
input.getFirstSection().getPageSetup().setSectionStart(SectionStart.NEW_PAGE);
input.getFirstSection().getHeadersFooters().linkToPrevious(false);
input.getFirstSection().getPageSetup().setRestartPageNumbering(true);
ImportFormatOptions importFormatOptions = new ImportFormatOptions();
importFormatOptions.setIgnoreHeaderFooter(false);
Above issue will resolve documentBuilder.insertDocument ?
Could you pls help me like is there any other way to merge different versions word document should merge and same layout/styles/font/footer/header…etc should maintain final merged document.
@rbandla3 Unfortunately, there is no way to keep different compatibility options for different parts of the document. This is simply impossible due to the MS Word document structure and there are no option which can resolve this.
No, documentBuilder.insertDocument will not also resolve this.
The only way to more or less keep the original document layout if they are merged into one is using Merger class with MergeFormatMode.KEEP_SOURCE_LAYOUT options as described above.
Another possible solution, if your target format is PDF, might be conversion each document to PDF separately and then merging the resulting PDF document into one document. Due to the fixed page nature of PDF documents their layout will not be changed after merging documents.
@alexey.noskov Merger.merge resolved above issue, but header/footer should maintain from original doc including page number. is there anyway to maintain same page number and header/footer from original same as like original doc.
Bydefault page number increasing based on linked to previous, but i have to maintain nunmbers based on original doc
is there a way to use this line along with merger…?
@rbandla3 Sure, you can achieve this using the following code:
Document[] files = new Document[]{
new Document("C:\\Temp\\input1.docx"),
new Document("C:\\Temp\\input2.docx"),
new Document("C:\\Temp\\input3.docx"),
new Document("C:\\Temp\\input4.docx"),
new Document("C:\\Temp\\input5.docx")
};
for (Document doc : files)
doc.getFirstSection().getPageSetup().setRestartPageNumbering(true);
Document output = Merger.merge(files, MergeFormatMode.KEEP_SOURCE_LAYOUT);
output.save("C:\\Temp\\out.docx");
Again i am landed same issue which has initial page break with above approach as it is internal using document.appendDocument(input, ImportFormatMode.KEEP_SOURCE_FORMATTING) and it’s causing page splitting
@rbandla3 Yes, I understand, that is why I have suggested the code that does exactly what you need. But the required Merger.merge method overload is available starting from 23.12 version of Aspose.Words. So yo use it you should update to this version or to the latest version of Aspose.Words.
Thank you so much for your support, above code resolved what exactly i need but, in my document i have to maintain page number customized like 1 to 30 pages, then again start 1 to 3 based on my word document, but above code those numbers continuing like 31,32,33 etc. in footer.
is there any way in the merger method to maintain page numbers as like source document with this function== Merger.merge(“C:\Temp\out.docx”, files, SaveFormat.DOCX, MergeFormatMode.KEEP_SOURCE_LAYOUT); == this resolving page split issue but page numbers not as like customized
here files== only String array
if we pass document array, again getting page split issue as like initial
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.