Headers spreading over the newly inserted document

This is what we’re expecting as well, but didn’t happen.
Please can you try the samples sent in first thread, as probably i didn’t express myself clear.
just create an empty console app and add this snippet in the Main:

Document docHead;
string docToAppend = @"NewDoc.odt";

Document document = new Document(@"CurrentDoc.odt");
DocumentBuilder builder = new DocumentBuilder(document);
docHead = new Document(docToAppend);

builder.MoveToDocumentStart();
builder.CurrentSection.HeadersFooters.LinkToPrevious(false);
builder.InsertDocument(docHead, ImportFormatMode.KeepSourceFormatting);
builder.InsertBreak(BreakType.SectionBreakNewPage);
document.Save(@"TestHead.odt");

@Remus87 When you use InsertDocument method, section from the original document is not preserved, only content is inserted into the current section in the document. In your case it would be more correct to use AppendDocument method to preserve section from the source document. For example see the following code:

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

In this case the first page does not have header, and the following pages have header.

Thanks, that seems to work. However, have to do several modifications now to accompany the AppendDocument method, and is quite not working as expected when appending another document at the end of the document.
Previously (when was using InsertDocument) was able to move through the document easily by making use of the Move method of the DocumentBuilder class and copy the documents at the desired location on the current document.
So now when trying to append Footer.doc as example at the end of the dst document it will inherit it’s headers from last section also. To replicate that just add the below in continuation to your last code supplied:

//also added this instance as a fix to not inherit headers style from dst document 
ImportFormatOptions importFormat = new ImportFormatOptions();
importFormat.IgnoreHeaderFooter = false;

Document docFoot = new Document(@"C:\Temp\FOOTER.DOC");
dst.AppendDocument(docFoot, ImportFormatMode.KeepSourceFormatting);

@Remus87 Please modify your code like the following , to prevent inheriting headers/footers from the previous section:

Document docFoot = new Document(@"C:\Temp\FOOTER.DOC");
docFoot.FirstSection.HeadersFooters.LinkToPrevious(false);
dst.AppendDocument(docFoot, ImportFormatMode.KeepSourceFormatting);

Thanks, solved the previous issue correctly the snippet provided.

However, the client spotted another fault, this time on the style preservation: the Indent of text is not accurate (see the IndentIssue.docx with screenshot for difference)
in continuation of the code just append the previous document to this one from the folder supplied -> “A newdoc May 15.docx” so that this new document to come first
docNewDoc.AppendDocument(document, ImportFormatMode.KeepSourceFormatting, importFormat);

Also tried to add page numbering on the final document following aspose sample as below but couldn’t

DocumentBuilder builder = new DocumentBuilder(docNewDoc);
builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary);
builder.Write("Page ");
builder.InsertField("PAGE", "");
builder.Write(" of ");  
builder.InsertField("NUMPAGES", "");

SampleIndent.zip (233.7 KB)

@Remus87

  1. I cannot reproduce the problem with indentation on my side. I have used an empty document as a target document and appended the document you have attached. Could you please also attach your target document here for testing? We will check the issue and provide you more information. Also, please try using the following code:
ImportFormatOptions opt = new ImportFormatOptions();
opt.KeepSourceNumbering = true;
dst.AppendDocument(src, ImportFormatMode.KeepSourceFormatting, opt);
  1. The code properly inserts footer on my side. But you should note, the code creates footer only in the first section in the document.

is already attached on the first Sample folder from first message on this thread. File name -> CurrentDoc.odt

Document dst = new Document(@"C:\Temp\A newdoc May 15.docx");
Document src = new Document(@"C:\Temp\CurrentDoc.odt");
dst.AppendDocument(src, ImportFormatMode.KeepSourceFormatting);

Can replicate in both directions. Either append dst to src, or the other way around.

@Remus87 Unfortunately, I cannot reproduce the problem on my side using the following code:

Document dst = new Document(@"C:\Temp\CurrentDoc.odt");
Document src = new Document(@"C:\Temp\A newdoc May 15.docx");
ImportFormatOptions opt = new ImportFormatOptions();
opt.KeepSourceNumbering = true;
dst.AppendDocument(src, ImportFormatMode.KeepSourceFormatting, opt);
dst.Save(@"C:\Temp\out.docx");

Seems the issue is the extension -> .ODT
Tried as .docx and worked fine.
Can you please try to save as .odt (as that’s our final format to generate)?

@Remus87
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): WORDSNET-26001

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

Any update on the ticket?

@Remus87 Unfortunately, there are no news regarding the issue yet. Currently it is in the queue for analysis.

Good morning! The issue is becoming a blocker for one of our clients and we kindly ask if can be treat as priority. Please let us know when is fixed

@Remus87 Unfortunately, there are no news regarding the issue yet. I have asked the responsible developer to take a look at it shortly. Please accept our apologies for your inconvenience.
You can obtain Paid Support Services if you need support on a priority basis.

ok Alexey, thanks for that. Waiting for the fix.

1 Like

Hi! Any updates on the ticket?

@Remus87 The issue is currently in analysis. We will keep you updated and let you know once the issue is resolved or we have more information for you.

The issues you have found earlier (filed as WORDSNET-26001) have been fixed in this Aspose.Words for .NET 23.12 update also available on NuGet.

We’ve tested and looks ok on MS Word. When opening with LibreOffice there’s still a minor indentation issue.
I’ve attached the necessary files to display the issue.
For now that should be ok, but maybe will be good to fix that also in the near future.

Thank you!
Samples.zip (148.8 KB)

@Remus87
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): WORDSNET-26592

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.