I want to read header from top and footer from botton positions from WORD document and the same settings we have to give in the final document
Hi
Thank you for inquiry. Please follow up the code snippet to import all header/footers from a document to another.
Section section = headerFooterSourceDocument.FirstSection;
// int importFormatMode = (keepSourceFormat) ? ImportFormatMode.KeepSourceFormatting: ImportFormatMode.UseDestinationStyles;
// Remove all HeaderFooter of the target document for each
// Section
for (int s = 0; s <document.Sections.Count; s++)
{
if (document.Sections[s].HeadersFooters != null)
{
while (document.Sections[s].HeadersFooters.Count != 0)
{
document.FirstSection.HeadersFooters.RemoveAt(0);
}
}
}
document.FirstSection.PageSetup.DifferentFirstPageHeaderFooter = section.PageSetup.DifferentFirstPageHeaderFooter;
document.FirstSection.PageSetup.OddAndEvenPagesHeaderFooter = section.PageSetup.OddAndEvenPagesHeaderFooter;
// Add content to the document (Import all HeaderFooter)
for (int i = 0; i <section.HeadersFooters.Count; i++)
{
// Import HeaderFooter
Node node = document.ImportNode(section.HeadersFooters[i], true, ImportFormatMode.KeepSourceFormatting);
// Insert header footer into the first section of
// document
document.FirstSection.HeadersFooters.Add(node);
}
Hope this will help.