Ejemplo n.º 1
0
        private PageSize GetPageSize(MyWordDocumentProperties pageProp)
        {
            PageSize pageSize = new PageSize();

            switch (pageProp.PageSize)
            {
            case MyPageSize.Letter:
                pageSize.Width = 12240; pageSize.Height = 15840;
                break;

            default:
                pageSize.Width = 11906; pageSize.Height = 16838;     // A4 page size
                break;
            }
            if (pageProp.PageOrientation == MyPageOrientation.Portrait)
            {
                pageSize.Orient = PageOrientationValues.Portrait;
            }
            else
            {
                pageSize.Orient = PageOrientationValues.Landscape;
                UInt32Value temp = pageSize.Width;
                pageSize.Width  = pageSize.Height;
                pageSize.Height = temp;
            }
            return(pageSize);
        }
Ejemplo n.º 2
0
        public MyWord(string path, MyWordDocumentProperties pageProp = null)
        {
            //initializing word document object
            this.path = path;
            wordProcessingDocument    = WordprocessingDocument.Create(new MemoryStream(), WordprocessingDocumentType.Document);
            mainDocumentPart          = wordProcessingDocument.AddMainDocumentPart();
            mainDocumentPart.Document = new Document();
            body = mainDocumentPart.Document.AppendChild(new Body());

            if (pageProp == null)
            {
                return;
            }

            //set some document properties
            PageSize pageSize = GetPageSize(pageProp);

            body.AppendChild(new SectionProperties(pageSize,
                                                   new PageMargin()
            {
                Top    = pageProp.Margins.TopMargin,
                Bottom = pageProp.Margins.BottomMargin,
                Left   = (uint)pageProp.Margins.LeftMargin,
                Right  = (uint)pageProp.Margins.RightMargin
            }
                                                   ));
        }