How to apply manuscript style to documents?


Is there any way to apply manuscript style to documents? Please refer to the input.docx and the output.docx for details.

Thanks for your help. (17.0 KB) (38.3 KB)

PS: After downloaded the sample files, the file extension “.zip” of them must be changed to “.docx”



In your output document, you have inserted GroupShape into document’s header. Instead of inserting group shape into document, we suggest you please set the border of paragraph. We suggest you please check the following code example and article. Hope this helps you.

Working with Paragraphs

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Set paragraph formatting properties
ParagraphFormat paragraphFormat = builder.ParagraphFormat;
paragraphFormat.Alignment = ParagraphAlignment.Center;
paragraphFormat.LeftIndent = 50;
paragraphFormat.RightIndent = 50;
paragraphFormat.SpaceAfter = 25;

Border topBorder = builder.ParagraphFormat.Borders[BorderType.Top];
topBorder.Color = Color.Red;
topBorder.LineWidth = 4.0d;
topBorder.LineStyle = LineStyle.DashSmallGap;

Border bottomBorder = builder.ParagraphFormat.Borders[BorderType.Bottom];
bottomBorder.Color = Color.Red;
bottomBorder.LineWidth = 4.0d;
bottomBorder.LineStyle = LineStyle.DashSmallGap;

// Output text
builder.Writeln("I'm a very nice formatted paragraph. I'm intended to demonstrate how the left and right indents affect word wrapping.");
builder.Writeln("I'm another nice formatted paragraph. I'm intended to demonstrate how the space after paragraph looks like.");
doc.Save(MyDir + "20.7.docx");

Thanks for your suggestion, however, that is not my need. What I expect is to add line borders line-by-line, not add borders within each paragraph or each page.

Please refer to the sample output file. (41.9 KB)

PS: After downloaded the sample output file, whose file extension “.zip” must be changed to “.docx”


In your document, the header contains the line and textbox shapes. If the paragraphs of document have different font size or different space after/before, the paragraphs do not fit on the correct line Shape.

However, you can use following code example to insert the shapes (line and textbox) into the header of document and insert the text into the document’s body. Hope this helps you.

Document doc = new Document();
doc.FirstSection.PageSetup.HeaderDistance = 50;

double pagewidth = doc.FirstSection.PageSetup.PageWidth
    - doc.FirstSection.PageSetup.LeftMargin - doc.FirstSection.PageSetup.RightMargin;

DocumentBuilder builder = new DocumentBuilder(doc);
builder.Font.Name = "Calibri";
builder.Font.Size = 10.5;
builder.ParagraphFormat.SpaceAfter = 6;

Shape rect = new Shape(doc, ShapeType.TextBox)
    Width = pagewidth,
    Height= 625,
    Stroke = { Color = Color.Blue },
    Left = 0,
    Top = 25
rect.BehindText = false;
int top = 25;
for (int i = 0; i < 21; i++)
    Shape line1 = new Shape(doc, ShapeType.Line)
        Width = pagewidth,
        Stroke = { Color = Color.Blue },
        Left = 0,
        Top = top
    top += 30;
builder.ParagraphFormat.SpaceAfter =6;

builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly;
builder.ParagraphFormat.LineSpacing = 24.0;

for (int i = 0; i < 50; i++)
    builder.Writeln("This is paragraph text"  +i);

doc.Save(MyDir + "20.6.docx");