Aspose.Words - AppendDocument adds blank space block randomly

Hello,
When I merge source document into target document using builder.Document.AppendDocument it randomly adds large blank/white spaces block on the page. Below is my code:

doc.FirstSection.PageSetup.SectionStart = SectionStart.NewPage;
doc.FirstSection.HeadersFooters.LinkToPrevious(false);

doc.FirstSection.PageSetup.RestartPageNumbering = true;
doc.FirstSection.PageSetup.PageStartingNumber = 1;


var formatOption = new ImportFormatOptions();
formatOption.IgnoreHeaderFooter = false;
formatOption.KeepSourceNumbering = true;

doc.FirstSection.PageSetup.PageWidth = dstDoc.LastSection.PageSetup.PageWidth;
doc.FirstSection.PageSetup.PageHeight = dstDoc.LastSection.PageSetup.PageHeight;
doc.FirstSection.PageSetup.Orientation = dstDoc.LastSection.PageSetup.Orientation;


//Iterate through all sections in the source document.
foreach (Paragraph para in doc.GetChildNodes(NodeType.Paragraph, true))
{
    para.ParagraphFormat.KeepWithNext = true;
}
builder.Document.AppendDocument(doc, ImportFormatMode.KeepSourceFormatting, formatOption);

attached is the screen shot of the blank/ white spaces on output document.

@kautilya Most likely this is caused by section break. When you append document whole section from the source document are appended to the target document. You can configure section start of the first section of the source document to void page break:

doc.FirstSection.PageSetup.SectionStart = SectionStart.Continuous;
builder.Document.AppendDocument(doc, ImportFormatMode.KeepSourceFormatting, formatOption);

But please note, this will work only if page setup of the neighbor section are the same.

My need is to start the appended document on new page, wouldn’t doc.FirstSection.PageSetup.SectionStart = SectionStart.Continuous; will cause to start on the same page where target document ends?

@kautilya Could you please attach your input, output nd expected output documents here for our reference? We will check the issue and provide you more information.

Apologies, I won’t be able to share the input doc. Is there any other way?

Adding “SectionStart.Continuous” is also not helping. It still adds white spaces.
image.png (7.4 KB)
The paragraph broken in half, resumed on next page
image.png (2.9 KB)

@kautilya You can create dummy documents that will allow us to reproduce the problem. Also, please note, it is safe to attach documents in te forum, only you as a topic starter and Aspose staff can see the attachments.

@alexey.noskov here I have attached output doc as well as input doc. you can observe empty white space under point 2.4, which resumes on next page. Also if you compare input doc has only 9 pages while the output doc is showing total 15 pages.

So, ideally it should be merged on target doc as is, should not add any extra white space and also the total page count should be correct. it should not count whole page. I already sent code used for append document.TestInput2_WhiteSpace_PageNumer.docx (66.3 KB)
output.docx (67.9 KB)

@kautilya Could you please also attach your target document? I have tested with the following simple code, i.e. append your source document to an empty document:

Document dst = new Document();
Document src = new Document(@"C:\Temp\in.docx");
dst.AppendDocument(src, ImportFormatMode.KeepSourceFormatting);
dst.Save(@"C:\Temp\out.docx");

and output document looks fine.

Hi,
I am generating target document on the fly. you can use first 5 page of the output document as target document.

@kautilya Unfortunately, I still cannot reproduce the problem on my side. If possible please create a simple console application that will allow us to reproduce the problem on our side. We will check and provide you more information.