.NET API to Manipulate Word Processing Documents

Open Source .NET Library to Create, Edit, Split or Join & Manage Custom Headers/Footers in Microsoft Word Files

DocX is an open source pure.NET library that enables software developers to create and manipulate Word 2007/2010/2013 files, in an easy manner. It is a lightweight and fast API that does not use COM libraries nor does it require Microsoft Office to be installed. The DocX API makes it easy to create and manipulate documents.

The API allows adding headers or footers to word documents. It can be the same on all the pages, or can be unique on the first page, or unique for odd or even word document pages. The great thing is that it can contain images, hyperlinks and more.

The API supports several important features such as apply a template to a Word document, modify word documents, join documents, recreate portions from one to another, document protection with or without password, set document margins, set page size, line spacing, indentation, text direction, text alignment, Manage fonts and font sizes, Create sections and many more.

Previous Next

Getting Started with DocX

First of all, you need to install .NET framework 4.0 and Visual Studio 2010 or later, in order to use DocX smoothly.

The recommended way to install is using NuGet

Install DocX from NuGet

 Install-Package DocX

Create & Modify Word Documents via .NET

The open source DocX API allows software developers to create new Word documents in DOCX file formats. The library also allows to modify the existing Word Documents according to user’s needs. The API also supports adding a picture, inserting a table and hyperlinks, adding paragraphs or bulleted list and a numbered list inside a word documents.

Create a DOCX File - C#

using (DocX document = DocX.Create("fileformat.docx"))
{
 // Add a new Paragraph to the document
 Paragraph pagagraph = document.InsertParagraph();
 // Append some text
 pagagraph.Append("File Format Developer Guide").Font("Arial Black");
 // Save the document
 document.Save();
}

Manage Custom Headers/Footers in Word Files

The DocX API enables Software developers to add custom headers and footers inside Word DOCX Documents. The API supports adding custom headers/footers with tables and pictures, paragraphs and charts. Once the document is created you can define the pages header's picture in a Table. Odd and even pages will have the same headers. You can also describe the pages footer's picture or text in a Table.

Create Header & Footer in DOCX - C#

//Create a document
using (DocX document = DocX.Create("FileFormat.docx"))
{
 // Add Header 
 document.AddHeaders();
 Header header = document.Headers.Odd;
 // Insert Paragraph in header
 Paragraph paragraph = header.InsertParagraph();
 paragraph.Append("File Format Developer Guide");
 // Add Footer 
 document.AddFooters();
 Footer footer = document.Footers.Odd;
 // Insert Paragraph in header
 Paragraph paragraph1 = footer.InsertParagraph();
 paragraph1.Append("File Format Develoer Guide");
 // Save Document
 document.Save();
}

Manipulate Image inside a Word Document

The DocX API allows software developers to programmatically manipulate images imbedded inside a Word DOCX documents. First of all, you need to have an image inside a word documents. To manipulate the image first you need to open the document and write a custom string or other changes you want to apply to an image and after that save the document.

Manipulate Images in a DOCX File - C#

using (DocX document = DocX.Load("FileFormat.docx"))
{
 // Read Image from word
 var image = document.Images[0];
 Bitmap bitmap = new Bitmap(image.GetStream(FileMode.Open, FileAccess.ReadWrite));
 Graphics graphics = Graphics.FromImage(bitmap);
 // Draw the string
 graphics.DrawString
 (
  "Manipulate Images using DocX",
  new System.Drawing.Font("Tahoma", 20),
  Brushes.Blue,
  new PointF(0, 0)
 );
 // Save document
 document.SaveAs("Output.docx");
}