16

How can I add a simple horizontal line in Migradoc so as to separate the content above the line from the content below the line?

Paragraph 1

Paragraph 2


Paragraph 3

ETC

rikket
  • 2,357
  • 7
  • 46
  • 74

3 Answers3

15

You can add a border to a paragraph or a table.

With respect to your sample, you could add a bottom border to paragraph 2 or add a top border to paragraph 3 or add a new paragraph between them and set either top or bottom border.

11

from this repo

        var hr = doc.AddStyle("HorizontalRule", "Normal");
        var hrBorder = new Border();
        hrBorder.Width = "1pt";
        hrBorder.Color = Colors.DarkGray;
        hr.ParagraphFormat.Borders.Bottom = hrBorder;
        hr.ParagraphFormat.LineSpacing = 0;
        hr.ParagraphFormat.SpaceBefore = 15;
vicentedealencar
  • 913
  • 1
  • 10
  • 20
  • 4
    I also had to add a line myParagraph.Format = hr.ParagraphFormat.Clone(); – Hoppe May 05 '17 at 14:46
  • 1
    You should edit your answer to include Hoppe's suggestion as the code snippet you posted doesn't do anything to the paragraph and his code is necessary to make it work. I would edit it, but any time I edit something it gets reverted anyway. – nasch Dec 04 '17 at 16:08
5

Late to the game, but here is an example of appending to the existing paragraph format, instead of overwriting as in the answer above, preserving already defined formats:

Paragraph p = new Paragraph();

p.Format.Alignment = ParagraphAlignment.Center;
//...any other formats needed
p.Format.Borders.Bottom = new Border() { Width = "1pt", Color = Colors.DarkGray };
cwalvoort
  • 1,851
  • 1
  • 18
  • 19