using Infragistics.Documents.Word;
string documentName = @"C:\TestWordDOMDoc.docx";
Document doc = new Document();
// Set the document properties, such as title, author, etc.
doc.DocumentProperties.Title = "Sample Document";
doc.DocumentProperties.Author = string.Format("Infragistics.{0}", SystemInformation.UserName);
Infragistics.Documents.Word.Font font = doc.CreateFont();
font.Bold = true;
font.Size = 15;
font.Underline = Underline.Double;
// Add a Paragraph to the document
Paragraph para1 = doc.ContentBlocks.AddParagraph();
para1.ContentRuns.AddTextRun("Sample Word Document with Hyperlinks,Images,Headers and Footers", font);
para1.ContentRuns.AddNewLine();
Paragraph para2 = doc.ContentBlocks.AddParagraph();
para2.ContentRuns.AddTextRun("Hyper link: ");
// Add a Hyperlink
para2.ContentRuns.AddHyperlink("http://www.infragistics.com", "Infragistics Inc.");
para2.ContentRuns.AddNewLine();
// Get Image
Image img = Image.FromFile(@"..\..\Ballon_New_Year.jpg");
// Add a paragraph to the Document
Paragraph para3 = doc.ContentBlocks.AddParagraph();
para3.ContentRuns.AddTextRun("Anchored Picture: An Anchored picture or image is one that is anchored to a specific location within the document. Unlike an inline picture, which moves along with adjacent content, an Anchored Picture remains at a fixed location within the paragraph, with adjacent text flowing around it.");
// Create an Anchored picture
AnchoredPicture anchPic = doc.CreateAnchoredPicture(img);
// Assign the picture outline properties for anchored image
anchPic.AlternateTextDescription = "Word Image";
anchPic.Outline.Color = Color.Brown;
anchPic.Outline.Style = PictureOutlineStyle.Single;
anchPic.Outline.LineWidth = 1;
// Add the Anchored picture to anchor section of the paragraph
para3.Anchors.AddAnchoredPicture(anchPic);
// Add a Paragraph to the document
Paragraph para4 = doc.ContentBlocks.AddParagraph();
para4.ContentRuns.AddTextRun("Inline Picture: An inline picture moves with the adjacent content");
// Create an Inline picture
InlinePicture inlinePic = doc.CreateInlinePicture(img);
inlinePic.AlternateTextDescription = "Word Image";
// Add the Inline picture to a content section of the paragraph
para4.ContentRuns.AddInlinePicture(inlinePic);
// Add a paragraph to the Document
Paragraph para5 = doc.ContentBlocks.AddParagraph();
// Add text to Paragraph
Section sec = doc.Sections.Add(para5);
// Header
Paragraph headerPara = sec.HeaderAllPages.ContentBlocks.AddParagraph();
// The header text alignment is set to right
headerPara.Properties.Alignment = ParagraphAlignment.Right;
// Create an Anchored Image to display in the Header
AnchoredPicture headeranchPic = doc.CreateAnchoredPicture(img);
// Display Anchored Image in Header
headerPara.Anchors.AddAnchoredPicture(headeranchPic);
// Display Text in Header
headerPara.ContentRuns.AddTextRun("This is a header");
//Footer
Paragraph footerPara = sec.FooterAllPages.ContentBlocks.AddParagraph();
// The footer text alignment is set to right
footerPara.Properties.Alignment = ParagraphAlignment.Right;
// Display Text in Footer
footerPara.ContentRuns.AddTextRun("This is a footer");
// Add Page numbers to the Footer
footerPara.ContentRuns.AddPageNumberField(PageNumberFieldFormat.Ordinal);
doc.Save(documentName);