Hello,
I’m testing evaluation version of Aspose.Words v25.3.0 before buying it. The task is to edit and save docx documents. But I’ve encountered with some issue which seems to be critical for my task.
When the source document has several sections with header and footer connected with help of “Link to Previous” option the result document has a lack of the “Link to Previous” option. As a result the headers and footers on the second section are missing.
Could you help me to understand what the problem this is?
I’ve attached the source and result docx documents. The program is simple - it just opens the source docx and saves it:
using Aspose.Words;
var src = @"..\LinkToPreviousSource.docx";
var res = @"..\LinkToPreviousResult.docx";
var docx = new Document(src);
docx.Save(res);
LinkToPreviousResult.docx (26.0 KB)
LinkToPreviousSource.docx (16.3 KB)
@SergeyD
It seems that you are experiencing an issue with the “Link to Previous” option for headers and footers not being preserved when saving a DOCX document using Aspose.Words. This can happen if the headers and footers are not properly linked in the code after loading the document.
To ensure that the “Link to Previous” setting is maintained, you can explicitly set the linking for the headers and footers after loading the document. Here’s how you can do it:
- Load the document.
- Iterate through the sections and set the headers and footers to link to the previous section.
Here’s an example of how you can modify your code:
using Aspose.Words;
var src = @"..\LinkToPreviousSource.docx";
var res = @"..\LinkToPreviousResult.docx";
var docx = new Document(src);
// Iterate through sections and link headers and footers
for (int i = 1; i < docx.Sections.Count; i++)
{
docx.Sections[i].HeadersFooters.LinkToPrevious(true);
}
docx.Save(res);
In this code, after loading the document, we loop through each section starting from the second one (index 1) and link its headers and footers to the previous section. This should help in preserving the “Link to Previous” setting when you save the document.
If you continue to face issues, please ensure that the source document has the headers and footers set up correctly before saving. You may also want to check if there are any specific settings in the document that could affect the linking behavior.
For more detailed information on working with headers and footers in Aspose.Words, you can refer to the official documentation on the LinkToPrevious method which provides examples and additional context on how to manage header and footer linking effectively.
If you have any further questions or need additional assistance, feel free to ask!
Thank you,
But, the thing is that the source document can be any document created by users, and I do not know whether the “Link to Previous” option should be enabled or disabled. If I always enable it, the user’s original formatting might be lost.
If this is a bug, is there a chance it will be fixed soon? Or is this an old issue, and the only way to avoid it is to manually set up “Link to Previous” every time?
Thanks,
SergeyD.
@SergeyD There two limitations in the free evaluation version of Aspose.Words:
- An evaluation watermark is injected in the documents.
- The maximum size of the processed document is limited to several hundreds of paragraphs.
Evaluation watermark is injects into the document’s header, so if header is not present (linked to previous) Aspose.Words creates it and header is no longer linked to previous. The problem will not occur in licensed mode.
I would suggest you to test Aspose.Words without evaluation version limitations, you can request a free 30-days temporary license .
Hello Alexey,
I’ve had such idea, but the evaluation mark is injected only to footer, but the header is also missing. So, you are sure this is an elevation related problem?
I’ll try to check if we can test Aspose.Words using temporary license.
Thanks,
SergeyD.
@SergeyD Yes, I am sure the problem is caused by evaluation mode. Here is document produced by the following simple code on my side (with license applied):
Document doc = new Document(@"C:\Temp\in.docx");
doc.Save(@"C:\Temp\out.docx");
out.docx (12.8 KB)