We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to insert line in Header or footer

Hi,

I am creating document file. Here i am creating Header with one image and some text. I want to put one line after that in next line, so can you help me how to insert line(straight line which comes under shapes in word document not new line(\r\n)).

Thanks
Raviranjan

Hi Raviranjan,


Thanks for your inquiry. Please use the following code snippet to insert the line in the Primary header of current section. The DocumentBuilder.MoveToHeaderFooter method moves the cursor to the beginning of a header or footer in the current section.

You can move the cursor to any place in Document and insert a Shape node of your choice by using the code like below:

DocumentBuilder builder = new DocumentBuilder();<o:p></o:p>

builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);

Shape line = new Shape(builder.Document, ShapeType.Line);

line.Width = 3 * 72;

builder.InsertNode(line);

builder.Document.Save(MyDir + "Out.docx");


Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.

Hi Tahir Manzoor,

Thanks for your reply. It’s working fine.

Thanks
Raviranjan Kumar Sinha

Hi Raviranjan,


Thanks for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.


Hi Tahir Manzoor ,

i want to insert line in the header and footer section.
Just below the header and Just above the footer.
Can you please help me out?

Thank you

Hi Raviranjan,


Thanks for your inquiry. Please use the following code example to insert line shape in header/footer of document.

Hope this helps you. Please let us know if you have any more queries.

Document doc = new Document();<o:p></o:p>

DocumentBuilder builder = new DocumentBuilder(doc);

builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary);

Shape lineShape = new Shape(doc, ShapeType.Line);

lineShape.Width = doc.FirstSection.PageSetup.PageWidth -

doc.FirstSection.PageSetup.LeftMargin -

doc.FirstSection.PageSetup.RightMargin;

builder.InsertNode(lineShape);

builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);

lineShape = new Shape(doc, ShapeType.Line);

lineShape.Width = doc.FirstSection.PageSetup.PageWidth -

doc.FirstSection.PageSetup.LeftMargin -

doc.FirstSection.PageSetup.RightMargin;

lineShape.WrapType = WrapType.Square;

lineShape.Left = 0;

lineShape.Top = builder.CurrentSection.PageSetup.HeaderDistance;

builder.InsertNode(lineShape);

doc.Save(MyDir + @"Out.docx");