Text styling (e.g. bold) inline in paragraph with Text Document API

When using the Text Document API, how is it possible to make a text part inside a paragraph bold?

For example:

When this is a paragraph it’s great when only this text is bold.

I’m still trying to fully understand the data structure here. One option could be to separate the above in three paragraphs:

  1. When this is a paragraph it’s great when only
  2. this text
  3. is bold.

and set pararaph 2 to bold. And then insert the paragraphs into the document with isInline set to true:
oDocument.InsertContent([oParagraph1], true);.
Here I’d have to insert them separately though, right? Since “Inline insert or not (works only for the last and the first element and only if it’s a paragraph).”

But I was wondering if there is a more straightforward way to style text inside a paragraph?

And just to understand, when I set a few words inside a paragraph to bold in the graphical editor, does this then result in separated inline paragraphs in the document’s internal data structure?

Hello @jakob

If the paragraph is already in the document, then you can use Search method first to find necessary text passage and then SetBold to set it as bold.

If you are constructing paragraph from scratch, you should rely on Runs. Use CreateRun to create small text block inside a paragraph, you use it to insert text run per run and set specific conditions to each of them.

No, selected text inherits bold attribute and it is mirrored in the document structure.

ApiRun is exactly what I was looking for. Thanks a lot @Constantine !

1 Like

Glad to help. Closing topic as solved.