Underline the header

Hi,

I’m trying to create an underlined header in my document, but i can’t get a good line.
I have as header, a table with 2 cells, (left some text, and right some text).

I found on this forum 2 ways to create a line, once with a shape and once with an underlined paragraph.
With the shape: I can get a line under te table, but i can’t get the line in the correct position because i have in even/odd pages different margins
This is the code:

Shape line = new Shape(doc, ShapeType.Line);
line.Width = HFTableWidth;
line.DistanceRight = rightMargin;
line.RelativeHorizontalPosition = RelativeHorizontalPosition.Page;
// line.HorizontalAlignment = Aspose.Words.Drawing.HorizontalAlignment.Center;
line.RelativeVerticalPosition = RelativeVerticalPosition.Paragraph;
line.StrokeColor = Color.Black;
line.Stroke.LineStyle = ShapeLineStyle.Single;
line.StrokeWeight = 1;
builder.InsertNode(line);

With the underlining paragraph, my line is to far from the table, it’s like a new paragraph that is underlined. When i try to underline the paragraph in de 2 cells, the line is open in the middle.

Do you know how i can get this part underlined ?
This is my code to create the header

builder.MoveToHeaderFooter(hftype);
builder.StartTable();
double tableWidth = HFTableWidth; 
builder.InsertCell();
builder.CellFormat.Width = tableWidth * 1 / 3;
builder.Write((docDate.HasValue) ? docDate.Value.ToString("dd MMM yyyy") : "");
builder.CurrentParagraph.ParagraphFormat.Alignment = ParagraphAlignment.Left;
builder.InsertCell();
builder.CellFormat.Width = tableWidth * 2 / 3;
builder.Write(headerTitle);
builder.CurrentParagraph.ParagraphFormat.Alignment = ParagraphAlignment.Right;
builder.EndRow();
builder.EndTable();

Hi

Thanks for your request. Maybe, in your case, you can just use table border. Please see the following code:

builder.MoveToHeaderFooter(hftype);
// Set row bottom border (you can also use cell bottom border)
builder.RowFormat.Borders.Bottom.LineStyle = LineStyle.Single;
builder.RowFormat.Borders.Bottom.LineWidth = 5;
builder.RowFormat.Borders.Bottom.Color = Color.Red;
// Biuld table
builder.StartTable();
double tableWidth = HFTableWidth;
builder.InsertCell();
builder.CellFormat.Width = tableWidth * 1 / 3;
builder.Write(docDate.ToString("dd MMM yyyy"));
builder.CurrentParagraph.ParagraphFormat.Alignment = ParagraphAlignment.Left;
builder.InsertCell();
builder.CellFormat.Width = tableWidth * 2 / 3;
builder.Write(headerTitle);
builder.CurrentParagraph.ParagraphFormat.Alignment = ParagraphAlignment.Right;
builder.EndRow();
builder.EndTable();

Hope this helps.

Best regards.

Thanks for your response

Unfortunately, the border is still not appearing

Hi

Thank you for additional information. This works fine on my side. I attached the output document for your reference.

Have you also tried setting cell border?

builder.CellFormat.Borders.Bottom.LineStyle = LineStyle.Single;
builder.CellFormat.Borders.Bottom.LineWidth = 5;
builder.CellFormat.Borders.Bottom.Color = Color.Red;

Also, please attach your output document.

Best regards.

Hi,

I just found out, that the red border appears on some pages, but not on all pages.
So maybe there is another problem.

You can find the file in attachment:
For your information:
Each group of chapters is added as a new section.
The code to build the header & footer is for every section the same.

Hi

Thanks for your request. Please make sure that the same code is used to insert header. Also, it would be great if you create simple application, which will allow me to reproduce the problem on my side.

Best regards.

Hi it’s difficult to simulate this in a small app because it’s actually a lot of processing stuff that goes on.

The code to insert the header is only coded once in a method. This method is called for every section. I’m 100% sure this is okay.

But, if you don’t know why it happens, you may leave this question. I will continue without the line.

I’m happy you solved my problem in the other topic i started :slight_smile:

Thanks

Hi

Thank you for additional information. Could you please show me the method, you use to insert header? I will check it and provide you more information.

Best regards.