Wrongly applied PageLayout column style on inserted document

Hi,

I am inserting 2 documents (one by one) into a destination document (TwoColumnsMasterContainer.docx) before specific SDT node.
First document (TwoColumnsFirstSection.docx) of one column PageLayout type and has only one paragraph.
Second document (TwoColumnsSecondSection.docx) is multi-section. First two sections are of one column PageLayout. Third is two columns type.
After inserting documents one by one in result document I got changed layout type for content from first document. It becomes two columns, that is not expected to be.

Code snippet :

public static void TwoColumnsTest()
{
    Aspose.Words.Document masterDocument = new Aspose.Words.Document(@"TwoColumnsMasterContainer.docx");
    StructuredDocumentTag nodeToInsertBefore = (StructuredDocumentTag)masterDocument.FirstSection.Body.GetChild(NodeType.StructuredDocumentTag, 0, true);

    Aspose.Words.Document firstInsertDoc = new Aspose.Words.Document(@"TwoColumnsFirstSection.docx");
    Aspose.Words.Document secondInsertDoc = new Aspose.Words.Document(@"TwoColumnsSecondSection.docx");

    InsertFile(firstInsertDoc, nodeToInsertBefore);
    InsertPageBreakBefore(masterDocument, nodeToInsertBefore);
    InsertFile(secondInsertDoc, nodeToInsertBefore);
    nodeToInsertBefore.RemoveNodeSafely();

    string documentName = @"~\Tmp\" + Guid.NewGuid() + ".docx";
    masterDocument.Save(documentName, SaveFormat.Docx);
}

Hi Rastko,

Thanks for your inquiry. Please see attached 16.4.0.docx document that is generated on my end using the following code and Aspose.Words for .NET 16.4.0:

Document doc = new Document(MyDir + @"TwoColumnsMasterContainer.docx");
Document doc1 = new Document(MyDir + @"TwoColumnsFirstSection.docx");
Document doc2 = new Document(MyDir + @"TwoColumnsSecondSection.docx");
doc.AppendDocument(doc1, ImportFormatMode.KeepSourceFormatting);
doc.AppendDocument(doc2, ImportFormatMode.KeepSourceFormatting);
doc.Save(MyDir + @"16.4.0.docx");

It does not seem to have reported problem. If this code is not acceptable for you and to ensure a timely and accurate response, please attach the following resources here for testing:

  • Aspose.Words generated output document showing the undesired behavior
  • Your expected document which shows the correct output. Please create this document using Microsoft Word application.
  • Please create a standalone console application (source code without compilation errors) that helps us reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we’ll start further investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip them and Click ‘Reply’ button that will bring you to the ‘reply page’ and there at the bottom you can include any attachments with that post by clicking the ‘Add/Update’ button.

Best regards,

Hi,

this does not describe my use case. I am inserting document after particular node. I am using DocumentBuilder. My fault is that I did not added helper method.

public static void TwoColumnsTest()
{
    Aspose.Words.Document masterDocument = new Aspose.Words.Document(@"TwoColumnsMasterContainer.docx");
    StructuredDocumentTag nodeToInsertBefore = (StructuredDocumentTag)masterDocument.FirstSection.Body.GetChild(NodeType.StructuredDocumentTag, 0, true);

    Aspose.Words.Document firstInsertDoc = new Aspose.Words.Document(@"TwoColumnsFirstSection.docx");
    Aspose.Words.Document secondInsertDoc = new Aspose.Words.Document(@"TwoColumnsSecondSection.docx");

    InsertFile(firstInsertDoc, nodeToInsertBefore);
    InsertPageBreakBefore(masterDocument, nodeToInsertBefore);
    InsertFile(secondInsertDoc, nodeToInsertBefore);
    nodeToInsertBefore.RemoveNodeSafely();

    string documentName = @"~\Tmp" + Guid.NewGuid() + ".docx";
    masterDocument.Save(documentName, SaveFormat.Docx);
}

private static void InsertFile(Aspose.Words.Document documentToInsert, Node nodeToInsertBefore)
{
    // We will be inserting into the parent of the destination paragraph.
    DocumentBuilder builder = new DocumentBuilder(nodeToInsertBefore.Document as Aspose.Words.Document);

    Aspose.Words.Paragraph newParagraph = new Aspose.Words.Paragraph(nodeToInsertBefore.Document);
    newParagraph.InsertNodeBefore(nodeToInsertBefore);

    builder.MoveTo(newParagraph);
    builder.InsertDocument(documentToInsert, ImportFormatMode.KeepSourceFormatting);
}

Thank you,
Rastko

Hi Rastko,

Thanks for your inquiry. We are working over your query and will get back to you soon.

Best regards,

Hi Rastko,

Sorry for the delayed response. A simplified workflow to get the desired output is as follows:

Document masterDocument = new Document(MyDir + "TwoColumnsMasterContainer.docx");
Document firstInsertDoc = new Document(MyDir + "TwoColumnsFirstSection.docx");
Document TwoColumnsSecondSection = new Document(MyDir + "TwoColumnsSecondSection.docx");
StructuredDocumentTag nodeToInsertBefore = (StructuredDocumentTag)masterDocument.FirstSection.Body.GetChild(NodeType.StructuredDocumentTag, 0, true);
Paragraph para = new Paragraph(masterDocument);
nodeToInsertBefore.ParentNode.InsertBefore(para, nodeToInsertBefore);
DocumentBuilder builder = new DocumentBuilder(masterDocument);
builder.MoveToDocumentStart();
builder.InsertDocument(firstInsertDoc, ImportFormatMode.KeepSourceFormatting);
builder.InsertBreak(BreakType.SectionBreakNewPage);
builder.InsertDocument(TwoColumnsSecondSection, ImportFormatMode.KeepSourceFormatting);
masterDocument.LastSection.Remove();
masterDocument.Save(MyDir + @"16.6.0.docx");

Generated document 16.6.0.docx is attached with this post. Hope, this helps.

Best regards,