Ejemplo n.º 1
0
        /// <summary>
        /// Returns a OpenXMl paragraph representing formatted listItem.
        /// </summary>
        /// <param name="item">listItem object</param>
        /// <param name="numStyleId">style id to use</param>
        /// <returns></returns>
        private static Paragraph GetListItem(Model.ListItem item, int numStyleId)
        {
            Paragraph listItemPara = new Paragraph();

            ParagraphProperties paraProps = new ParagraphProperties();

            NumberingProperties numberingProps = new NumberingProperties();
            NumberingLevelReference numberingLevelReference = new NumberingLevelReference() { Val = 0 };

            NumberingId numberingId = new NumberingId() { Val = numStyleId };

            numberingProps.Append(numberingLevelReference);
            numberingProps.Append(numberingId);
            paraProps.Append(numberingProps);

            Run listRun = new Run();
            Text listItemText = new Text()
            {
                Text = item.Body
            };
            listRun.Append(listItemText);

            listItemPara.Append(paraProps);
            listItemPara.Append(listRun);

            return listItemPara;
        }
        public static OpenXmlElement GetFormattedElement(Model.Paragraph paragraph)
        {
            Paragraph para = new Paragraph();
            para.Append(GetParagraphProperties(paragraph));

            foreach (Model.Element element in paragraph.SubElements)
            {
                if (element is Model.Text)
                {
                    Model.Text text = (Model.Text)element;
                    if (paragraph.Font != null && text.Font == null) text.Font = paragraph.Font;
                    para.Append(TextFormatter.GetFormattedElement(text));
                }
                else {
                    throw new InvalidSubFeatureException(paragraph.GetElementType().ToString(), element.GetElementType().ToString());
                }
            }

            return para;
        }
Ejemplo n.º 3
0
        public static OpenXmlElement GetFormattedElement(Model.Image image)
        {
            MainDocumentPart mainPart = DocumentPackager.GetInstance().GetMainPart();

            //Adding image part to main document part
            ImagePart imagePart = mainPart.AddImagePart(ImagePartType.Jpeg);

            if (image.ImageURL == null) throw new InvalidInputException("Input XML error : image location not provided for Image element.");

            using (FileStream stream = new FileStream(image.ImageURL, FileMode.Open))
            {
                imagePart.FeedData(stream);
            }

            var imageContent = GetImage(image, mainPart.GetIdOfPart(imagePart));

            var drawing = GetImage(image, mainPart.GetIdOfPart(imagePart));

            Model.Paragraph tmpImagePara = new Model.Paragraph();

            switch (image.HorizontalAlignment)
            {
                case DocGen.ObjectModel.HorizontalAlignment.Left:
                    tmpImagePara.Justification = Model.Justification.Left;
                    break;
                case DocGen.ObjectModel.HorizontalAlignment.Center:
                    tmpImagePara.Justification = Model.Justification.Center;
                    break;
                case DocGen.ObjectModel.HorizontalAlignment.Right:
                    tmpImagePara.Justification = Model.Justification.Right;
                    break;
            }

            Run imageRun = new Run();
            imageRun.Append(drawing);
            var imagePara = ParagraphFormatter.GetFormattedElement(tmpImagePara);
            imagePara.Append(imageRun);

            return imagePara;
        }
Ejemplo n.º 4
0
 public void AddElement(Paragraph paragraph)
 {
     elements.Add(paragraph);
 }
Ejemplo n.º 5
0
 public TableCell(Paragraph paragraph)
     : this()
 {
     elements.Add(paragraph);
 }