public void RemoveFooters() { //ExStart //ExFor:Section.HeadersFooters //ExFor:HeaderFooterCollection //ExFor:HeaderFooterCollection.Item(HeaderFooterType) //ExFor:HeaderFooter //ExFor:HeaderFooterType //ExId:RemoveFooters //ExSummary:Deletes all footers from all sections, but leaves headers intact. Document doc = new Document(MyDir + "HeaderFooter.RemoveFooters.doc"); foreach (Section section in doc.OfType <Section>()) { // Up to three different footers are possible in a section (for first, even and odd pages). // We check and delete all of them. HeaderFooter footer = section.HeadersFooters[HeaderFooterType.FooterFirst]; footer?.Remove(); // Primary footer is the footer used for odd pages. footer = section.HeadersFooters[HeaderFooterType.FooterPrimary]; footer?.Remove(); footer = section.HeadersFooters[HeaderFooterType.FooterEven]; footer?.Remove(); } doc.Save(MyDir + @"\Artifacts\HeaderFooter.RemoveFooters.doc"); //ExEnd }
public void RemoveFooters() { //ExStart //ExFor:Section.HeadersFooters //ExFor:HeaderFooterCollection //ExFor:HeaderFooterCollection.Item(HeaderFooterType) //ExFor:HeaderFooter //ExSummary:Shows how to delete all footers from a document. Document doc = new Document(MyDir + "Header and footer types.docx"); // Iterate through each section and remove footers of every kind. foreach (Section section in doc.OfType <Section>()) { // There are three kinds of footer and header types. // 1 - The "First" header/footer, which only appears on the first page of a section. HeaderFooter footer = section.HeadersFooters[HeaderFooterType.FooterFirst]; footer?.Remove(); // 2 - The "Primary" header/footer, which appears on odd pages. footer = section.HeadersFooters[HeaderFooterType.FooterPrimary]; footer?.Remove(); // 3 - The "Even" header/footer, which appears on odd even pages. footer = section.HeadersFooters[HeaderFooterType.FooterEven]; footer?.Remove(); Assert.AreEqual(0, section.HeadersFooters.Count(hf => !((HeaderFooter)hf).IsHeader)); } doc.Save(ArtifactsDir + "HeaderFooter.RemoveFooters.docx"); //ExEnd doc = new Document(ArtifactsDir + "HeaderFooter.RemoveFooters.docx"); Assert.AreEqual(1, doc.Sections.Count); Assert.AreEqual(0, doc.FirstSection.HeadersFooters.Count(hf => !((HeaderFooter)hf).IsHeader)); Assert.AreEqual(3, doc.FirstSection.HeadersFooters.Count(hf => ((HeaderFooter)hf).IsHeader)); }
public void RemoveFooters() { //ExStart //ExFor:Section.HeadersFooters //ExFor:HeaderFooterCollection //ExFor:HeaderFooterCollection.Item(HeaderFooterType) //ExFor:HeaderFooter //ExSummary:Deletes all footers from all sections, but leaves headers intact. Document doc = new Document(MyDir + "Header and footer types.docx"); foreach (Section section in doc.OfType <Section>()) { // Up to three different footers are possible in a section (for first, even and odd pages) // We check and delete all of them HeaderFooter footer = section.HeadersFooters[HeaderFooterType.FooterFirst]; footer?.Remove(); // Primary footer is the footer used for odd pages footer = section.HeadersFooters[HeaderFooterType.FooterPrimary]; footer?.Remove(); footer = section.HeadersFooters[HeaderFooterType.FooterEven]; footer?.Remove(); // All footers have been removed from the section's HeaderFooter collection, // so every remaining node is a header and has the "IsHeader" flag set to true Assert.AreEqual(0, section.HeadersFooters.Count(hf => !((HeaderFooter)hf).IsHeader)); } doc.Save(ArtifactsDir + "HeaderFooter.RemoveFooters.docx"); //ExEnd doc = new Document(ArtifactsDir + "HeaderFooter.RemoveFooters.docx"); Assert.AreEqual(1, doc.Sections.Count); Assert.AreEqual(0, doc.FirstSection.HeadersFooters.Count(hf => !((HeaderFooter)hf).IsHeader)); Assert.AreEqual(3, doc.FirstSection.HeadersFooters.Count(hf => ((HeaderFooter)hf).IsHeader)); }
public void RemoveFooters() { //ExStart:RemoveFooters Document doc = new Document(MyDir + "Header and footer types.docx"); foreach (Section section in doc) { // Up to three different footers are possible in a section (for first, even and odd pages) // we check and delete all of them. HeaderFooter footer = section.HeadersFooters[HeaderFooterType.FooterFirst]; footer?.Remove(); // Primary footer is the footer used for odd pages. footer = section.HeadersFooters[HeaderFooterType.FooterPrimary]; footer?.Remove(); footer = section.HeadersFooters[HeaderFooterType.FooterEven]; footer?.Remove(); } doc.Save(ArtifactsDir + "RemoveContent.RemoveFooters.docx"); //ExEnd:RemoveFooters }
public void RemoveHeaderFooterFeature() { Document doc = new Document(MyDir + "Document.docx"); foreach (Section section in doc) { section.HeadersFooters.RemoveAt(0); // Odd pages use the primary footer. HeaderFooter footer = section.HeadersFooters[HeaderFooterType.FooterPrimary]; footer?.Remove(); } doc.Save(ArtifactsDir + "Remove header and footer - Aspose.Words.docx"); }