Word bookmarks loose ID

Hi, Aspose team.

Scenario: Aspose.Words 25.4.0 breaks Word bookmark IDs when resaving a DOCX document. The sample document has 2 bookmarks in the footer.

Issue (actual behavior): If I resave a DOCX document with Aspose.Words 25.4, then bookmark IDs (0 and 1) in a footer have the incorrect value (0 and 0).

Expected behavior: Bookmark IDs in a footer have correct IDs after resaving – 0 and 1.

Other information: the issue can be replicated on the latest aspose.words 25.4. Sample file is attached. documentformat.openxml is used to verify bookmark IDs before and after resaving the doc.

document.docx (64.2 KB)

var path = @"./document.docx";
 
var oxml = WordprocessingDocument.Open(path, true);
var originalBookmarks = oxml.MainDocumentPart.FooterParts.ElementAt(0).RootElement.Descendants<DocumentFormat.OpenXml.Wordprocessing.BookmarkEnd>().ToList();
 
_ = originalBookmarks[0].Id == "0"
    ? true
    : throw new Exception("incorrect ID");
_ = originalBookmarks[1].Id == "1"
    ? true
    : throw new Exception("incorrect ID");
 
oxml.Close();
 
Aspose.Words.Document doc = new Aspose.Words.Document(path);
var newFileName = Path.Combine(Path.GetDirectoryName(path), Path.GetFileNameWithoutExtension(path) + "-resaved.docx");
var op = new OoxmlSaveOptions
{
    SaveFormat = SaveFormat.Docx
};
doc.Save(newFileName, op);
 
oxml = WordprocessingDocument.Open(newFileName, true);
var actualBookmarks = oxml.MainDocumentPart.FooterParts.ElementAt(1).RootElement.Descendants<DocumentFormat.OpenXml.Wordprocessing.BookmarkEnd>().ToList();
 
_ = actualBookmarks[0].Id == "0"
    ? true
    : throw new Exception("incorrect ID");
// NOT EXPECTED
_ = actualBookmarks[1].Id == "1"
    ? true
    : throw new Exception("incorrect ID");
 
oxml.Close();
 

Thanks.
For internal reference: MDP-22392.

@oleksii88 As I can see there is only ne bookmark in the attached document:

Could you please check whether you have attached the correct document for testing?

See the content of footer2.xml:

...
<w:bookmarkStart w:id="0" w:name="_Hlk175687234" />
...
<w:bookmarkStart w:id="1" w:name="_Hlk175687234" />
...

@oleksii88
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-28220

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.