public static Document GenerateDocument() { Document document1 = new Document() { MCAttributes = new MarkupCompatibilityAttributes() { Ignorable = "w14 wp14" } }; document1.AddNamespaceDeclaration("wpc", "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas"); document1.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006"); document1.AddNamespaceDeclaration("o", "urn:schemas-microsoft-com:office:office"); document1.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships"); document1.AddNamespaceDeclaration("m", "http://schemas.openxmlformats.org/officeDocument/2006/math"); document1.AddNamespaceDeclaration("v", "urn:schemas-microsoft-com:vml"); document1.AddNamespaceDeclaration("wp14", "http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing"); document1.AddNamespaceDeclaration("wp", "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"); document1.AddNamespaceDeclaration("w10", "urn:schemas-microsoft-com:office:word"); document1.AddNamespaceDeclaration("w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main"); document1.AddNamespaceDeclaration("w14", "http://schemas.microsoft.com/office/word/2010/wordml"); document1.AddNamespaceDeclaration("wpg", "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup"); document1.AddNamespaceDeclaration("wpi", "http://schemas.microsoft.com/office/word/2010/wordprocessingInk"); document1.AddNamespaceDeclaration("wne", "http://schemas.microsoft.com/office/word/2006/wordml"); document1.AddNamespaceDeclaration("wps", "http://schemas.microsoft.com/office/word/2010/wordprocessingShape"); DocumentBackground documentBackground1 = new DocumentBackground() { Color = "FF0000" }; V.Background background1 = new V.Background() { Id = "_x0000_s1025", BlackWhiteMode = Ovml.BlackAndWhiteModeValues.GrayScale, TargetScreenSize = Ovml.ScreenSizeValues.Sz1024x768 }; V.Fill fill1 = new V.Fill() { Type = V.FillTypeValues.Frame, Title = "Wedding_EnclosureCards", Recolor = true, Color = "FF0000" }; background1.Append(fill1); documentBackground1.Append(background1); Body body1 = new Body(); Paragraph paragraph1 = new Paragraph() { RsidParagraphAddition = "005F6C39", RsidRunAdditionDefault = "005F6C39" }; BookmarkStart bookmarkStart1 = new BookmarkStart() { Name = "_GoBack", Id = "0" }; BookmarkEnd bookmarkEnd1 = new BookmarkEnd() { Id = "0" }; paragraph1.Append(bookmarkStart1); paragraph1.Append(bookmarkEnd1); SectionProperties sectionProperties1 = new SectionProperties() { RsidR = "005F6C39" }; PageSize pageSize1 = new PageSize() { Width = (UInt32Value)12240U, Height = (UInt32Value)15840U }; PageMargin pageMargin1 = new PageMargin() { Top = 1440, Right = (UInt32Value)1440U, Bottom = 1440, Left = (UInt32Value)1440U, Header = (UInt32Value)720U, Footer = (UInt32Value)720U, Gutter = (UInt32Value)0U }; Columns columns1 = new Columns() { Space = "720" }; DocGrid docGrid1 = new DocGrid() { LinePitch = 360 }; sectionProperties1.Append(pageSize1); sectionProperties1.Append(pageMargin1); sectionProperties1.Append(columns1); sectionProperties1.Append(docGrid1); body1.Append(paragraph1); body1.Append(sectionProperties1); document1.Append(documentBackground1); document1.Append(body1); return document1; }
private static void BuildDocument(string fileName, List<TextPositon> listTextPositon) { using (WordprocessingDocument wordprocessingDocument = WordprocessingDocument.Create(fileName, WordprocessingDocumentType.Document)) { MainDocumentPart mainDocumentPart = wordprocessingDocument.AddMainDocumentPart(); Document doc = new Document(); Body body = new Body(); HeaderPart headerPart = mainDocumentPart.AddNewPart<HeaderPart>(); string headerRelationshipID = mainDocumentPart.GetIdOfPart(headerPart); Paragraph imageParagraph = AddImageParagraph(mainDocumentPart, listTextPositon); Text text = new Text("THIS IS A WONDERFUL WORLD!"); /* */ DocumentBackground documentBackground = new DocumentBackground() { Color = "FF0000" }; DocumentFormat.OpenXml.Vml.Background background = new DocumentFormat.OpenXml.Vml.Background() { Id = "_x0000_s1025", BlackWhiteMode = BlackAndWhiteModeValues.HighContrast, TargetScreenSize = ScreenSizeValues.Sz1024x768 }; DocumentFormat.OpenXml.Vml.Fill fill = new DocumentFormat.OpenXml.Vml.Fill() { Title = "TTTTTT", Recolor = true, RelationshipId = imageRelationshipID, Color = "FF0000" }; background.Fill = fill; documentBackground.Background = background; documentBackground.Append(imageParagraph); background.Append(fill); documentBackground.Append(background); doc.DocumentBackground = documentBackground; mainDocumentPart.Document = GenerateDocument(); mainDocumentPart.Document.Save(); wordprocessingDocument.Close(); } }