I’ve been looking through the information on the site trying to figure this out, but I think I’m just more confused than anything.
I have a document created in my .NET application where the last part of the document is generated in a loop. Each loop creates an area that may span multiple pages. What I would like to do is modify the page’s footer to include an identifier that shows which “loop” is on that page. For example, the looping part we will call “Element.” When the Element is being printed, I want to print the Element’s name in the footer on the left and the page numbers on the right, and only on the pages where there are “Elements.”
Is this even possible?
Hi Melinda,
Thanks for your inquiry. Yes, you can create/modify footer of Word document using Aspose.Words. In your case, we suggest you please create a table with two cells and one row in footer of table. Insert “Elements…” in first cell and page number in second cell. We suggest you please read following documentation links for your kind reference.
Use DocumentBuilder to Insert Document Elements
Using DocumentBuilder to Modify a Document Easily
Following code example shows how to create table in the footer of document and insert content. Hope this helps you.
Document doc = new Document(MyDir + "in.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary);
Table table = builder.StartTable();
// Insert a cell
builder.InsertCell();
builder.Write("Elements");
builder.InsertCell();
builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;
builder.InsertField(FieldType.FieldPage, true);
builder.EndRow();
builder.EndTable();
table.PreferredWidth = PreferredWidth.FromPercent(100);
// Remove border of table
table.ClearBorders();
table.AutoFit(AutoFitBehavior.AutoFitToWindow);
doc.Save(MyDir + "Out v16.6.0.docx");