How do I remove the first page but keep the headers and footers

can some one give me some C# code to remove the first blank page from this document but still keep the header and footers in the document. I have manged to get rid of the first page but I loose the header and footers in the rest of the document.

NP Tailgate Transmission Additional Signatures Form.zip (57.4 KB)

@cjmain

Please use the following code example to achieve your requirement. Hope this helps you.

Document doc = new Document(MyDir + "NP Tailgate Transmission Additional Signatures Form.docx");
MergeHeaderFooter(doc.Sections[0], doc.Sections[1], HeaderFooterType.HeaderFirst);
MergeHeaderFooter(doc.Sections[0], doc.Sections[1], HeaderFooterType.FooterFirst);
MergeHeaderFooter(doc.Sections[0], doc.Sections[1], HeaderFooterType.HeaderPrimary);
MergeHeaderFooter(doc.Sections[0], doc.Sections[1], HeaderFooterType.FooterPrimary);
doc.Sections[1].HeadersFooters.LinkToPrevious(false);
doc.Sections[0].Remove();
doc.Save(MyDir + "20.8.docx");

public static void MergeHeaderFooter(Section srcSec, Section dstSec, HeaderFooterType headerType)
{
    HeaderFooter header = dstSec.HeadersFooters[headerType];
    if (header == null)
    {
        // There is no header of the specified type in the current section, create it.
        header = new HeaderFooter(dstSec.Document, headerType);
        dstSec.HeadersFooters.Add(header);
    }

    foreach (Node srcNode in srcSec.HeadersFooters[headerType].ChildNodes)
    {
        Node dstNode = dstSec.Document.ImportNode(srcNode, true, ImportFormatMode.KeepSourceFormatting);
        header.AppendChild(dstNode);
    }
}
1 Like