This project has moved and is read-only. For the latest updates, please go here.

Odd and Even Footer Question

May 2, 2014 at 12:25 AM
Is it possible to have footers that have text on one end of the line and page number on the other end of the line? If so, how? I tried inserting a table but that did not work.

Odd Pages
PageNumber (justified left) BookTitle (justified right)
Even Pages
BookTitle (justified left) PageNumber (justified right)
May 5, 2014 at 3:38 AM
May 5, 2014 at 7:26 PM
Thank you, MadBoy. I had seen that but need to be able to do page numbering. I expect the "solution" will be to create the documents (there are at least 7), merge them and then do the footers in Word.
May 6, 2014 at 9:43 AM
Edited May 6, 2014 at 9:49 AM
Using the latest source code (which supports Footer.InsertTable) I think this should work:
//Add footers and get the (even) Footer
Footer evenFooter = document.Footers.even;
//Insert a table
Table t = evenFooter.InsertTable(1, 2);
//Add a paragraph with the book title to one cell
//Create a paragraph in the other cell and add a pagenumber to it
Paragraph pageNr = t.Rows[0].Cells[1].InsertParagraph();
pageNr.InsertPageNumber(PageNumberFormat.normal, 0);
There's one thing you should keep in mind though, you'll need the footers to be different on odd and even pages:
document.DifferentOddAndEvenPages = true;
This value seems to be lost when saving the DocX, however. I fixed that by adding this to the Save method in DocX.cs:
     mainDoc.Save(tw, SaveOptions.None);                 //<--This line already exists

using (TextReader tr = new StreamReader(settingsPart.GetStream()))
     settings = XDocument.Load(tr);

XElement body = mainDoc.Root.Element(w + "body");  //<-- This line exists => (w "plus" "body")
Marked as answer by MadBoy on 6/3/2014 at 4:22 AM
May 7, 2014 at 1:27 AM
Thanks for the help. I am a real novice when it comes to C# in VS so probably did something wrong. I inserted the using statement at line 3114 and got 132 errors. It had the correct statements on either side so I'll have some work to sort through it all. It may take a few days unless I'm lucky. I'll let you know how it turns out.
May 7, 2014 at 1:34 AM
All the errors refer to missing definitions which makes me think I have the wrong Docx.cs. Here is my assembly information:

[assembly: AssemblyVersion("")]
[assembly: AssemblyFileVersion("")]

Is this the same as what you are using?
May 7, 2014 at 9:29 AM
The Docx.cs I'm using is from the latest source code. It does say, I'm not sure if that means it's the same version.

You could download the source code, open the solution, edit Docx.cs and build the solution. Then you can use the Docx.dll from the output folder in your project.
Or you could add the DocX project to your solution and reference that.

This is my dll: download
May 9, 2014 at 11:06 PM
Well, I reopened VS2013 and loaded DocX. This time the dll compiled without error. I don't know what caused it to say so many variables were undefined. Thanks for your help.
Jun 3, 2014 at 12:22 PM
Annika89. I've added your change to main source code. Hopefully that's what you wanted.
Jun 4, 2014 at 9:43 AM
Thanks MadBoy, that's great :)