示例#1
0
        /// <summary>
        /// Gets a paragraph in ODF format.
        /// </summary>
        /// <param name="doc">The ODF Textdocument that is being created</param>
        /// <returns>List of paragraphs in ODF format.</returns>
        public virtual List <IContent> GetODFParagraph(AODL.Document.TextDocuments.TextDocument doc)
        {
            List <IContent> paragraphs = new List <IContent>();

            //Create the header, if there is any.
            if (_header != null)
            {
                paragraphs.Add(_header.GetODFParagraph(doc)[0]);
            }

            //Create the text part if there is any
            if (!string.IsNullOrEmpty(_text))
            {
                //Create the paragraph
                ODFParagraph paragraph = AODL.Document.Content.Text.ParagraphBuilder.CreateStandardTextParagraph(doc);
                //Add the formated text
                foreach (var formatedText in CommonDocumentFunctions.ParseParagraphForODF(doc, _text))
                {
                    paragraph.TextContent.Add(formatedText);
                }
                //Add the header properties
                paragraphs.Add(paragraph);
            }
            return(paragraphs);
        }
示例#2
0
        /// <summary>
        /// Creates an Run to replace the value in the custom tag.
        /// </summary>
        /// <returns></returns>
        private Run GenerateRunBlock()
        {
            Run run         = new Run();
            var stringValue = Value as string;

            if (!string.IsNullOrWhiteSpace(stringValue))
            {
                run.Append(CommonDocumentFunctions.ParseParagraphForOOXML(stringValue));
            }
            return(run);
        }
示例#3
0
        /// <summary>
        /// Creates sublists for nested lists.
        /// </summary>
        /// <param name="firstItem">The item to start the list with.</param>
        /// <param name="document">The document to which the sublist belongs.</param>
        /// <param name="currentIndex">The index of the item.</param>
        /// <returns>An ODF list</returns>
        protected AODL.Document.Content.Text.List GetODFSublist(ListItem firstItem, IDocument document, AODL.Document.Content.Text.List parentList, ref int currentIndex)
        {
            //Create a list
            AODL.Document.Content.Text.List list = new AODL.Document.Content.Text.List(document, parentList);

            //Set the level of the list
            int currentLevel = firstItem.Level;

            //Create a new list item
            AODL.Document.Content.Text.ListItem listItem = null;
            //Loop through the items
            while (currentIndex < Items.Count)
            {
                if (Items[currentIndex].Level > currentLevel)
                {
                    //Start a new list and append items.
                    listItem.Content.Add(GetODFSublist(Items[currentIndex], document, list, ref currentIndex));
                    continue;
                }
                if (Items[currentIndex].Level < currentLevel)
                {
                    //Stop this list.
                    break;
                }
                if (Items[currentIndex].Level == currentLevel)
                {
                    //Create a new list item
                    listItem = new AODL.Document.Content.Text.ListItem(document);
                    //Create a paragraph
                    var paragraph = ParagraphBuilder.CreateStandardTextParagraph(document);
                    //Add the text
                    foreach (var formatedText in CommonDocumentFunctions.ParseParagraphForODF(document, Items[currentIndex].Text))
                    {
                        paragraph.TextContent.Add(formatedText);
                    }

                    //Add paragraph to the list item
                    listItem.Content.Add(paragraph);

                    //Add the list item
                    list.Content.Add(listItem);

                    currentIndex++;
                }
            }

            return(list);
        }
示例#4
0
 /// <summary>
 /// Creates a ODF table row.
 /// </summary>
 /// <param name="row">The row in the ODF document.</param>
 /// <returns>The filled ODF row.</returns>
 internal AODL.Document.Content.Tables.Row GetODF(AODL.Document.Content.Tables.Row row)
 {
     foreach (string s in _values)
     {
         //Create a standard paragraph
         var paragraph = ParagraphBuilder.CreateStandardTextParagraph(row.Document);
         //Add the text
         foreach (var formatedText in CommonDocumentFunctions.ParseParagraphForODF(row.Document, s))
         {
             paragraph.TextContent.Add(formatedText);
         }
         //Add the content to the cell
         //row.Cells[_values.IndexOf(s)].Content.Add(paragraph);
     }
     return(row);
 }
示例#5
0
        /// <summary>
        /// Gets a list in ODF format.
        /// </summary>
        /// <param name="document">The document to which the list belongs.</param>
        /// <returns>The list as an IContent document</returns>
        public override IContent GetODFList(IDocument document)
        {
            //Create a list
            AODL.Document.Content.Text.List list = new AODL.Document.Content.Text.List(document, "NL1", ListStyles.Number, "NL1P1");

            //Set the list level to 0 as this is the top of the list
            int currentLevel = 0;

            //Create a new list item
            AODL.Document.Content.Text.ListItem listItem = null;
            //Loop through the items
            for (int currentIndex = 0; currentIndex < Items.Count; currentIndex++)
            {
                if (Items[currentIndex].Level > currentLevel)
                {
                    //Start a new list and append items.
                    if (listItem == null)
                    {
                        listItem = new AODL.Document.Content.Text.ListItem(document);
                    }
                    listItem.Content.Add(GetODFSublist(Items[currentIndex], document, list, ref currentIndex));
                    currentIndex--;
                    //Skip the rest of the routine
                    continue;
                }
                if (Items[currentIndex].Level == currentLevel)
                {
                    //Create a new list item
                    listItem = new AODL.Document.Content.Text.ListItem(document);
                    //Create a paragraph
                    var paragraph = ParagraphBuilder.CreateStandardTextParagraph(document);
                    //Add the text
                    foreach (var formatedText in CommonDocumentFunctions.ParseParagraphForODF(document, Items[currentIndex].Text))
                    {
                        paragraph.TextContent.Add(formatedText);
                    }

                    //Add paragraph to the list item
                    listItem.Content.Add(paragraph);

                    //Add the list item
                    list.Content.Add(listItem);
                }
            }

            return(list);
        }
示例#6
0
        /// <summary>
        /// Creates the text part of the paragraph.
        /// </summary>
        /// <param name="text">The text of the pargraph.</param>
        /// <returns>The paragraph or null if no text is defiend</returns>
        protected OOXMLParagraph CreateOOXMLTextPart(string text)
        {
            //Create the text part if there is any
            if (!string.IsNullOrEmpty(text))
            {
                OOXMLParagraph paragraph = new OOXMLParagraph(CommonDocumentFunctions.ParseParagraphForOOXML(text));
                //Add the header properties
                if (_paragraphLevel >= 0)
                {
                    paragraph.PrependChild(ooxmlParagraphProp(_paragraphLevel));
                }
                else if (!string.IsNullOrWhiteSpace(_styleName))
                {
                    paragraph.PrependChild(ooxmlParagraphProp(_styleName));
                }
                else
                {
                    paragraph.PrependChild(ooxmlParagraphProp(0));
                }
                return(paragraph);
            }

            return(null);
        }
示例#7
0
        /// <summary>
        /// Gets a paragraph in ODF format.
        /// </summary>
        /// <param name="doc">The ODF Textdocument that is being created</param>
        /// <returns>List of paragraphs in ODF format.</returns>
        public override List <IContent> GetODFParagraph(AODL.Document.TextDocuments.TextDocument doc)
        {
            //Get the headings enum
            Headings headingEnum   = Headings.Heading;
            string   headingString = string.Format("Heading{0}{1}", _paragraphLevel > 0 ? "_20" : string.Empty, _paragraphLevel > 0 ? "_" + (_paragraphLevel).ToString() : string.Empty);

            if (Enum.IsDefined(typeof(Headings), headingString))
            {
                headingEnum = (Headings)Enum.Parse(typeof(Headings), headingString);
            }

            //Create the header
            AODL.Document.Content.Text.Header header = new AODL.Document.Content.Text.Header(doc, headingEnum);
            //Add the formated text
            foreach (var formatedText in CommonDocumentFunctions.ParseParagraphForODF(doc, _text))
            {
                header.TextContent.Add(formatedText);
            }
            //Add the header properties
            return(new List <IContent>()
            {
                header
            });
        }
示例#8
0
        /// <summary>
        /// Replaces the text parts in the documents.
        /// </summary>
        /// <param name="mainPart">The document to search in.</param>
        /// <param name="imageCount">The number of images</param>
        private void ReplaceImage(MainDocumentPart mainPart, ref int imageCount)
        {
            Image image = Value as Image;

            if (image == null)
            {
                return;
            }

            //Find the tags in the body of the document. The tag value must correspond to the name provided in this object.
            //For images this is the SdtCell object.
            var sdtList = mainPart.Document.Descendants <SdtElement>().Where(s => s.SdtProperties.GetFirstChild <Tag>().Val.Value == Name).ToList();

            //Search the header part for the custom tag.
            foreach (var headerPart in mainPart.HeaderParts)
            {
                foreach (var element in  headerPart.Header.Descendants <SdtElement>().Where(s => s.SdtProperties.GetFirstChild <Tag>().Val.Value == Name).ToList())
                {
                    foreach (var run in element.Descendants <Run>().ToList().SelectMany(runs => runs))
                    {
                        //Find the image.
                        var images = run.Descendants <Drawing>().ToList();
                        if (images.Count != 1)
                        {
                            continue;
                        }
                        var drawing = images[0];
                        //When the image is found add the new image to the document.
                        string imageName;
                        imageCount++;
                        var rid = CommonDocumentFunctions.AddPictureToOOXMLDocument(headerPart, image, imageCount, out imageName);
                        //Replace the old image name and id wityh the new one.
                        var properties = drawing.Inline.DocProperties;
                        properties.Name = imageName;
                        //Find the picture object.
                        var picture = drawing.Inline.Graphic.GraphicData.Descendants <DocumentFormat.OpenXml.Drawing.Pictures.Picture>().ToList();
                        if (picture.Count != 1)
                        {
                            continue;
                        }
                        picture[0].BlipFill.Blip.Embed = rid;
                    }
                }
                //sdtList.AddRange(headerPart.Header.Descendants<SdtElement>().Where(s => s.SdtProperties.GetFirstChild<Tag>().Val.Value == Name).ToList());
            }
            //Search the footer for the custom tag.
            foreach (var footerPart in mainPart.FooterParts)
            {
                sdtList.AddRange(footerPart.Footer.Descendants <SdtElement>().Where(s => s.SdtProperties.GetFirstChild <Tag>().Val.Value == Name).ToList());
            }
            //Loop through the found items and replace the image. This will keep the formatting as is in the document.
            if (sdtList.Count <= 0)
            {
                return;
            }
            foreach (var run in sdtList.Select(block => block.Descendants <Run>().ToList()).SelectMany(runs => runs))
            {
                //Find the image.
                var images = run.Descendants <Drawing>().ToList();
                if (images.Count != 1)
                {
                    continue;
                }
                var drawing = images[0];
                //When the image is found add the new image to the document.
                string imageName;
                var    rid = CommonDocumentFunctions.AddPictureToOOXMLDocument(mainPart, image, 0, out imageName);
                //Replace the old image name and id wityh the new one.
                var properties = drawing.Inline.DocProperties;
                properties.Name = imageName;
                //Find the picture object.
                var picture = drawing.Inline.Graphic.GraphicData.Descendants <DocumentFormat.OpenXml.Drawing.Pictures.Picture>().ToList();
                if (picture.Count != 1)
                {
                    continue;
                }
                picture[0].BlipFill.Blip.Embed = rid;
            }
        }
示例#9
0
        /// <summary>
        /// Gets the picture in OOXMLFormat
        /// </summary>
        /// <param name="mainPart">The main part of the OOXML Document</param>
        /// <param name="index">The index of the image in the list of pargraphs.
        /// This is used for generating an identifier for the image</param>
        /// <param name="imageCount">The number of images in the document.
        ///  This is needed for the caption number</param>
        /// <returns>Picture in OOXML Document</returns>
        public List <OOXMLParagraph> GetOOXMLParagraph(OpenXmlPartContainer mainPart, int index, ref int imageCount)
        {
            var imageName = string.Empty;
            var rid       = CommonDocumentFunctions.AddPictureToOOXMLDocument(mainPart, _image, index, out imageName);

            var paragraph =
                new OOXMLParagraph(
                    new Run(
                        new RunProperties(
                            new NoProof()),
                        new Drawing(
                            new wp.Inline(
                                new wp.Extent {
                Cx = 5274945L, Cy = 3956050L
            },
                                new wp.EffectExtent {
                LeftEdge = 19050L, TopEdge = 0L, RightEdge = 1905L, BottomEdge = 0L
            },
                                new wp.DocProperties {
                Id = (UInt32Value)1U, Name = imageName, Description = _text
            },
                                new wp.NonVisualGraphicFrameDrawingProperties(
                                    new a.GraphicFrameLocks {
                NoChangeAspect = true
            }),
                                new a.Graphic(
                                    new a.GraphicData(
                                        new pic.Picture(
                                            new pic.NonVisualPictureProperties(
                                                new pic.NonVisualDrawingProperties {
                Id = (UInt32Value)0U, Name = _text
            },
                                                new pic.NonVisualPictureDrawingProperties()),
                                            new pic.BlipFill(
                                                new a.Blip {
                Embed = rid, CompressionState = a.BlipCompressionValues.Print
            },
                                                new a.Stretch(
                                                    new a.FillRectangle())),
                                            new pic.ShapeProperties(
                                                new a.Transform2D(
                                                    new a.Offset {
                X = 0L, Y = 0L
            },
                                                    new a.Extents {
                Cx = 5274945L, Cy = 3956050L
            }),
                                                new a.PresetGeometry(
                                                    new a.AdjustValueList()
                                                    )
            {
                Preset = a.ShapeTypeValues.Rectangle
            }))
                                        )
            {
                Uri = "http://schemas.openxmlformats.org/drawingml/2006/picture"
            })
                                )
            {
                DistanceFromTop = (UInt32Value)0U, DistanceFromBottom = (UInt32Value)0U, DistanceFromLeft = (UInt32Value)0U, DistanceFromRight = (UInt32Value)0U
            }))
                    );

            var paragraphs = new List <DocumentFormat.OpenXml.Wordprocessing.Paragraph> {
                paragraph
            };

            //Add the caption if there is one.
            if (!string.IsNullOrEmpty(_text))
            {
                paragraphs.Add(captionParagraph(_text, ref imageCount));
            }
            return(paragraphs);
        }