Word Control Spire.Doc [Header and Footer] Tutorial (12): Adjust the height of the header and footer in the Word document from C#

Spire.Doc for .NET is a .NET class library specialized in manipulating Word documents. It helps developers create, edit, convert and print Microsoft Word documents easily, quickly and efficiently without installing Microsoft Word. With nearly 10 years of professional development experience, the Spire series of office document development tools focus on creating, editing, converting and printing Word/PDF/Excel and other file formats, compact and convenient. 

The E-iceblue  functional class library Spire series document processing components are all developed by a local Chinese team, do not rely on third-party software, are not restricted by other countries' technology or laws and regulations, and are also compatible with domestic operating systems such as Zhongke Fangde, Winning Kirin, etc. Compatible with domestic document processing software WPS (such as .wps/.et/.dps and other formats

Spire.Doc for.NET latest download (qun:767755948) icon-default.png?t=N2N8https://www.evget.com/product/3368/download

The height of the header and footer can be adjusted using the HeaderDistance and FooterDistance properties. Below are the detailed steps to use Spire.Doc to adjust the header and footer height of a word document.

detailed steps:

Step 1    Create a document object and load the word document.

Document doc = new Document();
doc.LoadFromFile("Headers and Footers.docx");

Step 2    Create a section.

Section section = doc.Sections[0];

Step 3    Adjust the height of the header and footer in the section.

section.PageSetup.HeaderDistance = 100;
section.PageSetup.FooterDistance = 100;

Step 4: Save the file.

doc.SaveToFile("Output.docx", FileFormat.Docx2013);

screenshot :

header:

footer:

Full code:

//Instantiate a Document object
Document doc = new Document();
//Load the word document
doc.LoadFromFile("Headers and Footers.docx");

//Get the first section
Section section = doc.Sections[0];

//Adjust the height of headers in the section
section.PageSetup.HeaderDistance = 100;

//Adjust the height of footers in the section
section.PageSetup.FooterDistance = 100;

//Save the document
doc.SaveToFile("Output.docx", FileFormat.Docx2013);

The above is a tutorial on how to adjust the height of the header and footer in a Word document from C#. If you have other questions, you can continue to browse this series of articles to get related tutorials. You can also leave me a message or join our official website Technical exchange group.

Guess you like

Origin blog.csdn.net/m0_67129275/article/details/130100514