23

In MigraDoc, if I have a paragraph, how can I only bold some text in the paragraph, not the entire paragraph.

Edit: Below is the typical code I would use to add a bolded paragraph.

var paragraph = section.AddParagraph("This text");
paragraph.Format.Font.Bold = true;

I can't just add separate paragraphs splitting the text, because MigraDoc puts space between the paragraphs.

contactmatt
  • 18,116
  • 40
  • 128
  • 186
  • Can you post the code that you are currently using to bold the entire paragraph? I'm guessing you will need to split up the paragraph into 'spans' (or whatever PDFSharp uses) and style each one individually. – Chris Laplante Sep 13 '12 at 21:33
  • It's a little more difficult than that. PDFSharp has its own library that handles all of that. – contactmatt Sep 13 '12 at 21:48
  • I wasn't suggesting using an HTML `span`; I was questioning if PDFSharp has a way of breaking text elements into multiple elements that can be accessed individually. – Chris Laplante Sep 13 '12 at 21:50

1 Answers1

34

Try the following lines:

var paragraph = section.AddParagraph("This text"); 

paragraph.AddFormattedText("Text in Bold Style", TextFormat.Bold); 
Victor
  • 653
  • 5
  • 9
  • 1
    Worth noting that named styles can be also used for the 2nd argument of `AddFormattedText()`. This is useful when applying more than one formatting to the text. – ajeh Apr 30 '18 at 17:12