Bold font for BookMark text Alone
Hi All,
Unable to set styles for bookmark text alone. Trying to create extension, please find below code. I can only see option to set font styles for entire paragraph, not a single bookmark. Am I missing something.
public static void ProcessBookMark(this DocX doc, string BookMarkName, string BookMarkValue, bool? Bold = false)
{
var Bm = doc.Bookmarks[BookMarkName];
if (Bm != null)
{
Bm.SetText(BookMarkValue);
Bm.Paragraph.Font("Arial");
if (Bold==true)
Bm.Paragraph.Bold();
}
}
Hi, Thank you for reporting this. We will investigate to fix this.
Do you have a update on this. The main issue that I see is that the Sample in the BookmarkSample.cs is replacing the text for a bookmark that already has formatted text and replacing the text with "Formatted Bookmark has been changed". But it doesn't keep the formatting if you have placeholder Bookmark, example a blank bookmark with no text. You also can't set the text format because the bookmark is return the text at the paragraph level. You can get around this by having text in the bookmark and replacing the text or getting the bookmark and then appending the text to the paragraph as long as the text is at the end of the paragraph. But you can't set the style of the text/run.
var formattedBookmark2 = document.Bookmarks["formattedBookmark2"]; if (formattedBookmark2 != null) { formattedBookmark2.SetText("Formatted Bookmark has been changed2"); } DocumentWithBookmarks.docx
Notice that on FormattedBookmark2 it is Arial Black 12 vs Calibri 11. But it reverts to Calibri 11 after the text was added vs SetText.
Hi,
This feature will be available in v1.8. Thank you.