Appending 2 documents with SectionStart.Continuous changes justification on first document

I am merging multiple documents together into a single document using AppendDocument(). I wish to avoid page-breaks between documents, and so on the second document I set the SectionStart to be SectionStart.Continuous.

However, the formatting on the last-line from the first paragraph changes. In the original document, the paragraph is fully justified. But the text on the last line is not long enough to be fully justified, so the last line remains left justified. This is the desired affect. (see attached screen shots)

When I append the 2nd document to continue from the end of the first, the justification on that last-line changes to be fully justified. This results in huge gaps/white space on the last line, and is not desirable.

This behavior can be reproduced in Aspose by doing the following:

new Aspose.Words.License().SetLicense("Aspose.Total.lic");
var doc = new Document("first.doc");
var doc2 = new Document("second.doc");

doc2.LastSection.PageSetup.SectionStart = SectionStart.Continuous;
doc.AppendDocument(doc2, ImportFormatMode.UseDestinationStyles);

doc.Save("result.doc");

I have attached my sample documents that are referenced in this code. This behavior can also be reproduced directly in word by doing the following:

  1. Enter a paragraph of text, and set to fully justified. Keep the last line short enough to not fully justify
  2. At the end of that paragraph, do an Page Layout -> Breaks -> Continuous, and you’ll get a newline but the justification will have changed.
  3. You can “undo” this format change by going to the end of the changed line, and simply hitting “enter”. It will clear the format change but keep the newline below. I have tried mimicking this behavior from Aspose but have not been successful.

Are there any recommendations for combining 2 documents in a continuous fashion (no page breaks), but leave the formatting of the paragraphs alone?

Hi Orion,

Thanks for your inquiry.

Please note that Aspose.Words mimics the same behavior as MS Word does. In your case, I suggest you please use the following code snippet to achieve your requirements. I have attached the output document with this post for your kind reference.

var doc = new Document(MyDir + "first.doc");
var doc2 = new Document(MyDir + "second.doc");
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveToDocumentEnd();
builder.Writeln("");
doc2.FirstSection.PageSetup.SectionStart = SectionStart.Continuous;
doc.AppendDocument(doc2, ImportFormatMode.UseDestinationStyles);
doc.Save(MyDir + "result.doc");

Thank you, that appears to have worked. I was trying all sorts of different control characters, but I had somehow missed Builder and WriteLn()

Hi Orion,

Thanks for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.