Help needed for appending Word documents when sidebar/overlay is involved

Hello

We are currently evaluating Aspose Words for .NET to help us automate the production of transcription reports but have run into an issue. I have attached a zip file containing 5 documents outlining the issue. The five documents are:

  1. Main Template.doc
  2. Leader.doc
  3. Body.doc
  4. Trailer.doc
  5. Current Output.doc

The goal is to merge #2, #3 & #4 in order into the Main Template. However, as #5 (Current Output.doc) shows that we cannot seem to adjust the settings so that we can get it to render to the right of the overlay side bar containing the doctors names. We tried changing the left margin setting of the body document and although it does move to the right of the sidebar on the 1st page, the same margin setting continues into the next page where we instead would like to fall back to use the normal margin when it does not encounter the side bar from page 2 and beyond. Any advice or pointers would be greatly appreciated as we are in a rush to address this issue and want to move forward with purchase of licenses.

Thanks!

Hi there,

Thanks for your inquiry. The shared .zip file have size 0kb. Could you please reattach it again? We will then provide you more information about your query along with code.

Hi Tahir

I am not sure what happened, but I have attached them again. Please have a look and let me know if you are able to download them now.

Thanks a bunch!

Subrams

Hi there,

Thanks for sharing the documents. In your case, we suggest you please use following code example to achieve your requirements. Hope this helps you. We have attached the output document with this post for your kind reference. Please let us know if you have any more queries.

Document doc = new Document(MyDir + "Main Template.doc");
Document Leader = new Document(MyDir + "Leader.doc");
Document Body = new Document(MyDir + " Body.doc");
Document Trailer = new Document(MyDir + "Trailer.doc");
Double leftindent = doc.LastSection.Body.LastParagraph.ParagraphFormat.LeftIndent;
doc.FirstSection.Body.AppendParagraph("");
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveToDocumentEnd();
builder.InsertDocument(Leader, ImportFormatMode.KeepSourceFormatting);
builder.InsertDocument(Body, ImportFormatMode.KeepSourceFormatting);
builder.InsertDocument(Trailer, ImportFormatMode.KeepSourceFormatting);
foreach (Paragraph paragaph in doc.GetChildNodes(NodeType.Paragraph, true))
{
    paragaph.ParagraphFormat.LeftIndent = leftindent;
}
Shape shape = (Shape)doc.FirstSection.Body.FirstParagraph.GetChild(NodeType.Shape, 0, true);
foreach (Paragraph paragaph in shape.GetChildNodes(NodeType.Paragraph, true))
{
    paragaph.ParagraphFormat.LeftIndent = 0.0;
}
LayoutCollector collector = new LayoutCollector(doc);
foreach (Paragraph paragaph in doc.GetChildNodes(NodeType.Paragraph, true))
{
    if (collector.GetStartPageIndex(paragaph) > 1)
        paragaph.ParagraphFormat.LeftIndent = 0.0;
}
doc.Save(MyDir + "Out.doc");

Thanks a lot, Tahir. This really helps. Appreciate the quick turn around on this issue.

Hi Tahir

I tried this code against the same documents, and get a null returned from this line of code for the value of the shape variable:

Shape shape = (Shape)doc.FirstSection.Body.FirstParagraph.GetChild(NodeType.Shape, 0, true);

Any idea why?

Thanks again!

Saravanan

Hi Saravanan,

Thanks for your inquiry. You are using Aspose.Words without license. Please note that in evaluation mode there are some limitations applied. E.g Aspose.Words injects an evaluation watermark at the top of the document. The document’s content are truncated after a certain number of paragraphs during import or export.

Please request for temporary license from here:
Get temporary license

Please read about applying license from here:
Applying a License