sanddy19 wrote:
thanks for this solution, it worked great for my needs!
Here's another rendition:
public static Paragraph AddHorizontalRule(Section section, Unit fontSize, double percentWidth,
Color? color = null)
{
double percent = ((percentWidth <= 0.0 || percentWidth > 100.0) ? 100.0 : percentWidth) / 100.0;
Color hrColor = color ?? MigraDocColors.TextGray;
Unit contentWidth = section.PageSetup.PageWidth - section.PageSetup.LeftMargin - section.PageSetup.RightMargin;
Unit indentSize = (contentWidth - (percent * contentWidth)) / 2.0;
Paragraph paragraph = section.AddParagraph();
paragraph.Format.LeftIndent = indentSize;
paragraph.Format.RightIndent = indentSize;
paragraph.Format.Font.Size = fontSize;
paragraph.Format.Shading.Color = hrColor;
paragraph.Format.LineSpacingRule = LineSpacingRule.Single;
paragraph.Format.Borders.Visible = false;
return paragraph;
}
Pass in a font size of "0.5" and you'll get a single horizontal line that is the same thickness as the default border thickness. You can define your own default color (I like dark gray, #666666). The method above lets you define a percent width, and the horizontal rule is centered horizontally regardless. Note that the method above also returns a Paragraph, and the default Paragraph.Format.SpaceBefore and SpaceAfter are going to be zero. Depending on the form, I'll add a little space before and after, e.g. "0.15cm".
Have fun!
Brian