Header/Footer with Different First Page set

Home Forums Open-Xml-PowerTools Header/Footer with Different First Page set

This topic contains 5 replies, has 2 voices, and was last updated by  Thierry 7 years, 8 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #3371

    Thierry
    Participant

    Hi Eric,

    I am using the DocumentBuilder to build a document.

    The template document consist of one header/footer with a Different First Page set for the Title Page of the document.

    The ‘SectionProperties’ of the template document looks like this:
    <w:sectPr w:rsidRPr=”009F70F0″ w:rsidR=”009F686A” w:rsidSect=”005C2099″ xmlns:w=”http://schemas.openxmlformats.org/wordprocessingml/2006/main”>
    <w:headerReference w:type=”default” r:id=”rId9″ xmlns:r=”http://schemas.openxmlformats.org/officeDocument/2006/relationships” />
    <w:footerReference w:type=”default” r:id=”rId10″ xmlns:r=”http://schemas.openxmlformats.org/officeDocument/2006/relationships” />
    <w:pgSz w:w=”11906″ w:h=”16838″ />
    <w:pgMar w:top=”1205″ w:right=”1418″ w:bottom=”1418″ w:left=”1418″ w:header=”709″ w:footer=”709″ w:gutter=”0″ />
    <w:cols w:space=”720″ />
    <w:titlePg />
    <w:docGrid w:linePitch=”360″ />
    </w:sectPr>

    When using the doucmentbuilder to insert a document like this:

    string source1 = “../../Template.docx”;
    string source2 = “../../~mvi52qa2vp.docx”; //Document to insert
    List<Source> sources = null;
    sources = new List<Source>()
    {
    new Source(new WmlDocument(source1), true),
    new Source(new WmlDocument(source2), “InsertFile”)
    };
    DocumentBuilder.BuildDocument(sources, Path.Combine(tempDi.FullName, “Out3.docx”));

    The header/footer of the source1 are kept indeed, however the header/footer appears also in the Title Page.

    Could you give me some support on this issue?

    Kind Regards,
    Thierry

    #3373

    Eric White
    Keymaster

    Hi Thierry,

    I’m not fully clear on your issue. Looking at the markup, there is no header/footer for the first page – only for default.

    -Eric

    #3375

    Thierry
    Participant

    Hi Eric,

    Thank you for your response. The ‘Template.docx’ (source1) has indeed no header/footer for the first page. However, when using the doucmentbuilder to insert a document like this:

    string source1 = “../../Template.docx”;
    string source2 = “../../~mvi52qa2vp.docx”; //Document to insert
    List<Source> sources = null;
    sources = new List<Source>()
    {
    new Source(new WmlDocument(source1), true),
    new Source(new WmlDocument(source2), “InsertFile”)
    };
    DocumentBuilder.BuildDocument(sources, Path.Combine(tempDi.FullName, “Out3.docx”));

    The header/footer of the source1 are kept indeed, however the header/footer appears also in the Title Page.

    This is the result of the ‘SectionProperties’ of ‘Out3.docx’:
    <w:sectPr w:rsidRPr=”009F70F0″ w:rsidR=”009F686A” w:rsidSect=”005C2099″ xmlns:w=”http://schemas.openxmlformats.org/wordprocessingml/2006/main”>
    <w:footerReference w:type=”first” r:id=”Ra87d0c97f7434292″ xmlns:r=”http://schemas.openxmlformats.org/officeDocument/2006/relationships” />
    <w:footerReference w:type=”even” r:id=”Ra2200a8bb40749b4″ xmlns:r=”http://schemas.openxmlformats.org/officeDocument/2006/relationships” />
    <w:headerReference w:type=”first” r:id=”Ra92ab269d2f341d0″ xmlns:r=”http://schemas.openxmlformats.org/officeDocument/2006/relationships” />
    <w:headerReference w:type=”even” r:id=”R0b83a566dd124f96″ xmlns:r=”http://schemas.openxmlformats.org/officeDocument/2006/relationships” />
    <w:headerReference w:type=”default” r:id=”R78559284577b419c” xmlns:r=”http://schemas.openxmlformats.org/officeDocument/2006/relationships” />
    <w:footerReference w:type=”default” r:id=”R481d720143dd4244″ xmlns:r=”http://schemas.openxmlformats.org/officeDocument/2006/relationships” />
    <w:pgSz w:w=”11906″ w:h=”16838″ />
    <w:pgMar w:top=”1205″ w:right=”1418″ w:bottom=”1418″ w:left=”1418″ w:header=”709″ w:footer=”709″ w:gutter=”0″ />
    <w:cols w:space=”720″ />
    <w:titlePg />
    <w:docGrid w:linePitch=”360″ />
    </w:sectPr>

    Is this caused by ‘source2’? For now, I don’t want to use ‘KeepSections’ for this source.
    I tried to set ‘KeepSections’ of source2 to false unfortunately, but this didn’t help.

    I hope you can give me some hints or support for this problem.

    Kind regards,
    Thierry

    #3376

    Eric White
    Keymaster

    Are ‘first page’ and ‘title page’ synonymous in your description of the issue?

    Is there a title page in the template document, which does not have a header/footer?

    I have a suspicion about the source of your problem. There was another bug in DocumentBuilder, where if a section contained a ‘first’, header, and then if there was another section that had the option ‘Link to Previous’ set, then it would ‘inherit’ the even and default headers/footers from the previous section, which is almost certainly not what was wanted. Therefore DocumentBuilder ‘fleshes out’ the headers and footers for a section, copying, for instance, the default header to the first and even header, if they were not set. I am not certain about the exact dynamics of the bug that you are seeing, but I suspect it is in this area.

    I am under a deadline that prohibits me from spending much time, but here is a plan:

    • For now, after running DocumentBuilder, you can open the document, and ‘tweak’ the headers and footers to get them to be exactly as you wish.
    • Also, please post your documents on DropBox or OneDrive, so I can test with them.

    I need a more exact, precise description of your issue, for example:

    • In the template document there are two(?) sections. The first section has headers and footers set for even, default, and first, (or whatever). The first header has such and such. The default header has blah blah. The section section has only the ‘default’ header. It contains …. And so on. Please be very precise.
    • The inserted document has only the default section, which has the ???? headers and footers. However, I am setting keepSections to false, and these sections do not show up in the generated document.
    • And so on. This is only an example. I need to know precisely what your situation is, and what is the erroneous behavior.

    After I complete my current project, as soon as is possible, I can take a look.

    However, it is pretty easy to open up a document and tweak the headers / footers, so this will get you going, so your project is not blocked.

    -Eric

    #3386

    Thierry
    Participant

    Hi Eric,

    Hereby more information on the issue.
    – The template document contains section where the Title Page contains a ’empty’ First Page Header and First Page Footer (so no header and footer is defined for this Title Page). The following pages (page 2 and further) contains a header and footer. In this header and footer the option ‘Different First Page’ is checked.
    – The inserted document has only the default section, which contain one empty header and footer.
    However, I am setting ‘keepSections’ to false, and this section does not show up in the generated document.

    The problem is that the ‘First Page Header’ and ‘First Page Footer’ of the Title Page of the generated document contains the content of the header and footer of second page.

    The three documents (Flow.docx, ~mvi52qa2vp.docx and Out3.docx) can be downloaded at:
    documents

    – Flow.docx ==> template document
    – ~mvi52qa2vp.docx ==> document to insert
    – Out3.docx ==> gegenerated document

    Kind regards,
    Thierry

    #3741

    Thierry
    Participant

    Hi Eric,

    I eventually solved the issue.
    The problem was in the ‘template document’. The headers/footers where not for each section defined.
    When this was done, the problem disappeared 🙂
    So when all headers/footers in the sections are correctly defined it works as expected.

    Kind Regards,
    Thierry

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.