Hi,
I am inserting a bookmark at the start and end of the Structured Document Tag (SDT) so I can identify it. However, when I insert a content control in the entire table in fixed HTML, the first rows cell’s div is not placed at the top but is inserted after some divs. As a result, my bookmark is not set at the beginning of the SDT. How can I solve this issue?
Snippet :
NodeCollection runs = null;
IEnumerable<Node> sdts = doc.GetChildNodes(NodeType.StructuredDocumentTag, true).Where(x => ((StructuredDocumentTag)x).Tag != null && ((StructuredDocumentTag)x).Tag != "");
foreach (StructuredDocumentTag sdt in sdts)
{
int stdPageIndex = LayoutCollector.GetStartPageIndex(sdt);
runs = sdt.GetChildNodes(NodeType.Run, true);
InsertSdtStartBookMark(ref doc, stdPageIndex, sdt, runs.FirstOrDefault());
InsertSdtEndBookMark(ref doc, stdPageIndex, sdt, runs.LastOrDefault());
}
doc.UpdatePageLayout();
private void InsertSdtStartBookMark(ref Document doc, int pageIndex, StructuredDocumentTag sdt, Node run)
{
try
{
string sdtStartBookmarkName = $"sdt_s_{pageIndex}_{sdt.Tag}";
run.ParentNode.InsertBefore(new BookmarkStart(doc, sdtStartBookmarkName), run);
run.ParentNode.InsertBefore(new BookmarkEnd(doc, sdtStartBookmarkName), run);
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
}
private void InsertSdtEndBookMark(ref Document doc, int pageIndex, StructuredDocumentTag sdt, Node run)
{
try
{
string sdtEndBookmarkName = $"sdt_e_{pageIndex}_{sdt.Tag}";
run.ParentNode.InsertAfter(new BookmarkEnd(doc, sdtEndBookmarkName), run);
run.ParentNode.InsertAfter(new BookmarkStart(doc, sdtEndBookmarkName), run);
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
}
Word Sample :
ColspanTable.docx (57.5 KB)
Bookmark start name : sdt_s_1_7f8320c7-5448-4ec3-87a1-a3cfadbc89c3
Bookmark end name : sdt_e_1_7f8320c7-5448-4ec3-87a1-a3cfadbc89c3
Fixed HTML output :
Output.zip (59.8 KB)
Screenshot for HTML fixed structure: