DocX icon indicating copy to clipboard operation
DocX copied to clipboard

Bold font for BookMark text Alone

Open PrasanthKumarVinakota opened this issue 7 years ago • 3 comments

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();
        }
    }

PrasanthKumarVinakota avatar Jun 26 '18 10:06 PrasanthKumarVinakota

Hi, Thank you for reporting this. We will investigate to fix this.

XceedBoucherS avatar Jul 10 '18 15:07 XceedBoucherS

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.

ShevekAnarre avatar Feb 04 '20 22:02 ShevekAnarre

Hi,

This feature will be available in v1.8. Thank you.

XceedBoucherS avatar Feb 05 '20 15:02 XceedBoucherS