Topic:   How to create word document with headers and footers and save it as xps in C#
Oct 22, 2020 06:33 1 Replies 909 Views SAI

   How to create word document with headers and footers and save it as xps in C#

Prev Next
Topic Replies (1)
  1. 1
    idnkx user


    Firstly, create a word document with headers and footers, then save the word file via Docx.

    Secondly, load the word file and save it as xps file by using spire.doc.

    Before starting your project you need download the docx.dll and the free spire.doc to your computer and then reference them.

    There are main steps of the method:

    Step1: create a word file with headers and footers and then save the word file via Docx.

    using (DocX document = DocX.Create(@"docs\HeadersAndFooters.docx"))


    // Add Headers and Footers to this document.



    // Force the first page to have a different Header and Footer.

    document.PageHeight = 500;

    document.DifferentFirstPage = true;

    // Get the first Headers for this document.

    Header header_first = document.Headers.first;

    // Get the first Footer for this document.

    Footer footer_first = document.Footers.first;

    Paragraph p0 = header_first.InsertParagraph("Hello First Header.", false, formatting);

    Paragraph p1 = footer_first.InsertParagraph();

    P1.Append("Hello First Footer.").Alignment = Alignment.right;

    Paragraph p2 = document.InsertParagraph();

    P2.AppendLine("Hello First page.");






    Load the word document and save it as xps. The Docx library don't support convert file format. So we need use the free Spire.Doc which support convert word document to other format file, such as pdf, html, rtf and xps.

    The below code show you how to convert word document to xps file via spire.doc.

    //load word file

    Document doc = new Document();


    //save word document as xps file


Leave a Reply
Guest User

Not sure what course is right for you?

Choose the right course for you.
Get the help of our experts and find a course that best suits your needs.

Let`s Connect