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.