Odd and Even Footer Question

May 1, 2014 at 11:25 PM
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.

Example
Odd Pages
PageNumber (justified left) BookTitle (justified right)
Even Pages
BookTitle (justified left) PageNumber (justified right)
Developer
May 5, 2014 at 2:38 AM
May 5, 2014 at 6: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 8:43 AM
Edited May 6, 2014 at 8:49 AM
Using the latest source code (which supports Footer.InsertTable) I think this should work:
//Add footers and get the (even) Footer
document.AddFooters();
Footer evenFooter = document.Footers.even;
//Insert a table
Table t = evenFooter.InsertTable(1, 2);
//Add a paragraph with the book title to one cell
t.Rows[0].Cells[0].InsertParagraph("BookTitle");
//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 12:27 AM
Annika89,
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 12: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("1.0.1.13")]
[assembly: AssemblyFileVersion("1.0.1.13")]

Is this the same as what you are using?
May 7, 2014 at 8:29 AM
The Docx.cs I'm using is from the latest source code. It does say 1.0.1.13, 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 10: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.
Developer
Jun 3, 2014 at 11:22 AM
Annika89. I've added your change to main source code. Hopefully that's what you wanted.
Jun 4, 2014 at 8:43 AM
Thanks MadBoy, that's great :)