Question

How to set up paragraph width in MigraDoc? All what I imagine is create table and set the column width and then paragraph populate all width. But I need something like next:

var paragraph016 = section.AddParagraph();
paragraph016.Format.Borders.Bottom.Visible = true;
paragraph016.Format.WidowControl = true;
//here must be define paragraph width

Or maybe anybody know how can I draw line on the page, where I can setup width and position of my line?

Was it helpful?

Solution 2

You can set the width indirectly by specifying left and right indent. I don't know if this leads to the desired line, but it's worth a try.

A table will work.

An image would also work - best with a vector image (could be PDF), but a raster image with a single pixel in the desired color should also work.

OTHER TIPS

I use paragraph width as a part of my 'add a horizontal rule' helper method. Using left and right indent works great:

public static void AddHorizontalRule(Section section, double percentWidth, Color? color = null)
{
    double percent = (percentWidth < 0.0 || percentWidth > 1.0) ? 1.0 : percentWidth;
    Color hrColor = color ?? new Color(96, 96, 96); // Lt Grey default

    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.Borders.Top.Visible = true;
    paragraph.Format.Borders.Left.Visible = false;
    paragraph.Format.Borders.Right.Visible = false;
    paragraph.Format.Borders.Bottom.Visible = false;
    paragraph.Format.Borders.Top.Color = hrColor;
}

Note that because a section's PageSetup values are 0 and therefore use the default document settings, that to use the client area width as shown above, you need to explicitly set these values in the section.PageSetup before calling this method. I do it this way so that I don't have to pass around the document nor depend on document.LastSection being the section that I am working on. I just pass in a Section object and have at it.

Enjoy! Brian

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top