Set text as bold

  • 13 Views
  • Last Post 5 weeks ago
FaL keN posted this 17 December 2018

 Hello,

I get tex block with one paragraph. How can I make this text bold?

I tried:

IParagraph paragraph = paragraphs.getElement(0);
ICharParams params = engine.CreateCharParams();
paragraph.GetCharParams(0, params);
params.setIsBold(true);
paragraph.SetCharParams(0, paragraph.getLength(), params, 0,1);

But this doesn't work.

Thank you.

Nadezhda A. Solovyeva posted this 5 weeks ago

Hello,

Most likely, in your code, you refer to an incorrect paragraph. You may set all text in your document bold using the code below. Please make sure that you run the code after you have performed the document synthesis.

 

        private void ApplyBold(FRDocument document)
        {
            FREngine.ICharParams bold = engineLoader.Engine.CreateCharParams();
            bold.IsBold = true;

            foreach (FREngine.FRPage page in document.Pages)
            {
                foreach (FREngine.IBlock block in page.Layout.Blocks)
                {
                    if (block.Type != BlockTypeEnum.BT_Text)
                    {
                        continue;
                    }
                    foreach (FREngine.IParagraph paragraph in block.GetAsTextBlock().Text.Paragraphs)
                    {
                        paragraph.SetCharParams(0, paragraph.Length, bold, 0 /*keep flags*/, (int)StyleParamsEnum.SF_Bold); 
                    }
                }
            }
        }

Close