Header line appearing at top of pages

The attached document shows a mysterious header line at the top of page 3 right in the middle of a loop where the software is printing a set of user data:

AddSectionHeader(builder, "AFFILIATIONS & COMMUNITY INVOLVEMENT");
foreach (var aff in resumeData.Affiliations)
{
    if (string.IsNullOrEmpty(aff.CandidateAffiliation.Description))
    {
        builder.ParagraphFormat.SpaceAfter = 10;
        builder.Writeln(aff.CandidateAffiliation.Name);
    }
    else
    {
        builder.Writeln(aff.CandidateAffiliation.Name);
        builder.ParagraphFormat.SpaceAfter = 10;
        builder.Writeln(aff.CandidateAffiliation.Description);
    }
    builder.ParagraphFormat.SpaceAfter = 0;
}

AddSectionHeader method does the following in an attempt to print a divider line followed by the header text:

builder.ParagraphFormat.ClearFormatting();
builder.Writeln(string.Empty);
builder.Font.Bold = true;
builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
builder.ParagraphFormat.SpaceAfter = 10;
builder.ParagraphFormat.Borders.Top.LineWidth = 2.0;
builder.ParagraphFormat.Borders.Top.LineStyle = LineStyle.Single;
builder.ParagraphFormat.Borders.Top.Color = COLOR_DARK_BLUE;
builder.Font.Size = FONT_SIZE_HEADER;
builder.Writeln(text);
builder.ParagraphFormat.SpaceAfter = 0;
builder.Font.Size = FONT_SIZE_NORMAL;
builder.Font.Bold = false;

I’m guessing it may have to do with the page setup somehow, but why not until page 3–shouldn’t it also manifest on page 2? I don’t want the line there. I only want the border to show when printing a header with AddSectionHeader. Most of the code building this document follows a similar pattern: print a header, iterate an array of text, possibly change some spacing, print text, loop.

Can anyone explain this or know how to fix it?

Hi Benjamin,

Thanks for your inquiry. It would be great if you please share following detail for investigation purposes.

  • Please attach your input Word document.
  • Please

create a standalone/runnable simple application (for example a Console
Application Project
) that demonstrates the code (Aspose.Words code) you used to generate
your output document

  • Please attach the output Word file that shows the undesired behavior.
  • Please
    attach your target Word document showing the desired behavior. You can
    use Microsoft Word to create your target Word document. I will
    investigate as to how you are expecting your final document be generated
    like.

Unfortunately,
it is difficult to say what the problem is without the Document(s) and
simplified application. We need your Document(s) and simple project to
reproduce the problem. As soon as you get these pieces of information to
us we’ll start our investigation into your issue.

See attached for the following (inside Documents.zip:)

  • Program.cs - simplified version that produces the problem (see top of page 3)
  • resume.docx - the problem document similar to original attachment

I don’t have a target document, otherwise I wouldn’t have a problem. To clarify, I need to know why the header line is appearing at the top of pages 3 and beyond. If you need to see the problem beyond page 3, add more strings of text to the array returned by GetSomeText().

Thanks in advance!

Hi Benjamin,

Thanks for sharing the detail. Please use ParagraphFormat.Borders.Top.LineStyle = LineStyle.None in AddSectionHeader method. See the highlighted code snippet. I have attached the output document with this post for your kind reference.

Please let us know if you have any more queries.

private static void AddSectionHeader(DocumentBuilder builder, string text)
{
    builder.ParagraphFormat.ClearFormatting();
    builder.Writeln(string.Empty);
    builder.Font.Bold = true;
    builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
    builder.ParagraphFormat.SpaceAfter = 10;
    builder.ParagraphFormat.Borders.Top.LineWidth = 2.0;
    builder.ParagraphFormat.Borders.Top.LineStyle = LineStyle.Single;
    builder.ParagraphFormat.Borders.Top.Color = COLOR_DARK_BLUE;
    builder.Font.Size = FONT_SIZE_HEADER;
    builder.Writeln(text);
    builder.ParagraphFormat.SpaceAfter = 0;
    builder.Font.Size = FONT_SIZE_NORMAL;
    builder.Font.Bold = false;
    builder.ParagraphFormat.Borders.Top.LineStyle = LineStyle.None;
}