C#: Online Guide
How To: Word SDK
Header & Footer Processing
Header & Footer Processing
  |  
Home ›› XDoc.Word ›› C# Word: Process Header & Footer

C# Word - Header & Footer Processing in C#.NET


Provide a Series of Methods to Process Footer & Header in Word Document for C# Users




Overview



By using C#.NET Word document header & footer processing Interface control (XDoc.Word).//More TODO, users are able to process header and footer on Word document.


Related .net document control helps:
asp.net mvc pdf editor using c#: ASP.NET MVC PDF Editor: view, annotate, redact, edit PDF document in C# ASP.NET MVC
asp.net pdf editor using c#: EdgePDF: ASP.NET PDF Editor Web Control: Online view, annotate, redact, edit, process, convert PDF documents
c# asp.net pdf document viewer: ASP.NET PDF Document Viewer in C#: view, annotate, redact Adobe PDF files online in ASP.NET
c# asp.net iis document viewer: C# HTML5 Viewer: Deployment on IIS
asp.net webforms pdf editor using c#: ASP.NET WebForms PDF Editor: create, view, edit, annotate, redact PDF file in ASP.NET WebForms application
c# asp.net image viewer: ASP.NET Image Document Viewer Control: view, annotate, redact, convert image files in html web browser
c# asp.net mvc document viewer: ASP.NET MVC Document Viewer: view, annotate, redact files on ASP.NET MVC web projects




C# DLLs: Word Header and Footer Processing



Add references:


  RasterEdge.Imaging.Basic.dll


  RasterEdge.XDoc.Office.Inner.Common.dll


  RasterEdge.Imaging.Drawing.dll


  RasterEdge.Imaging.Processing.dll


  RasterEdge.XDoc.Office.Inner.Office03.dll


  RasterEdge.Imaging.Font.dll


  RasterEdge.XDoc.Word.dll


  RasterEdge.XImage.Raster.Core.dll


  RasterEdge.XImage.Raster.dll


Use corresponding namespaces;


  using RasterEdge.Imaging.Basic;


  using RasterEdge.XDoc.Word;




Create Footer & Header



The following C# sample code will show you how to create a header and footer in section. There's no content in section until blocks are created in it.




String docFilePath = @"";
//Open the document
DOCXDocument document =DOCXDocument.Open(docFilePath);
//Get the main document
IDocument doc = document.GetDocument();
//Create a section
ISection section = doc.CreateSection(0);
//Create a header for section
IHeader header = section.CreateHeader(HeaderAndFooterType.Default);
//More TODO:may create some block in header.

//Create a footer for section
IFooter footer = section.CreateFooter(HeaderAndFooterType.Default);
//More TODO:may create some block in footer.

//Save the document
doc.Save(@"");





Create and Add Paragraph to Footer & Header



Like main body story, header and footer of Word also contains a series of blocks such as normal paragraphs and tables. And we provide various methods to process them, the following demo code will show you how to create paragraph in header and footer.




String docFilePath = @"";
//Open the document
DOCXDocument document = DOCXDocument.Open(docFilePath);
//Get the main document
IDocument doc = document.GetDocument();
//Create a section for document
ISection section = doc.CreateSection(0);
//Create a header for section
IHeader header = section.CreateHeader(HeaderAndFooterType.Default);
//Just Show how to Create a paragraph for header
IParagraph paragraph = header.CreateParagraph();
//Create a run and text in paragraph
IRun run = paragraph.CreateARun();
run.CreateText("Header");

//MORE TODO:
//
//
doc.Save(@"");





Create and Add Table to Footer & Header



The following demo code shows how to create table in footer and header.




String docFilePath = @"";
//Open the document
DOCXDocument document = DOCXDocument.Open(docFilePath);
//Get the main document
IDocument doc = document.GetDocument();
//Create a section for document
ISection section = doc.CreateSection(0);
//Create a header for section
IHeader header = section.CreateHeader(HeaderAndFooterType.Default);
//Just show how to Create a table for header
ITable table= header.CreateTable(3, 3);
//MORE TODO:
//
//
doc.Save(@"");