コード例 #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
ファイル: Row.cs プロジェクト: smallkid/aodl
        /// <summary>
        /// Merge cells. This is only possible if the rows table is part
        /// of a text document.
        /// </summary>
        /// <param name="document">The TextDocument this row belongs to.</param>
        /// <param name="cellStartIndex">Start index of the cell.</param>
        /// <param name="mergeCells">The count of cells to merge incl. the starting cell.</param>
        /// <param name="mergeContent">if set to <c>true</c> [merge content].</param>
        public void MergeCells(AODL.Document.TextDocuments.TextDocument document, int cellStartIndex, int mergeCells, bool mergeContent)
        {
            try
            {
                this.CellCollection[cellStartIndex].ColumnRepeating = mergeCells.ToString();

                if (mergeContent)
                {
                    for (int i = cellStartIndex + 1; i < cellStartIndex + mergeCells; i++)
                    {
                        foreach (IContent content in this.CellCollection[i].Content)
                        {
                            this.CellCollection[cellStartIndex].Content.Add(content);
                        }
                    }
                }

                for (int i = cellStartIndex + mergeCells - 1; i > cellStartIndex; i--)
                {
                    this.CellCollection.RemoveAt(i);
                    this.CellSpanCollection.Add(new CellSpan(this, (AODL.Document.TextDocuments.TextDocument) this.Document));
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
コード例 #3
0
        /// <summary>
        /// Creates the text document table.
        /// </summary>
        /// <param name="document">The document.</param>
        /// <param name="tableName">Name of the table.</param>
        /// <param name="styleName">Name of the style.</param>
        /// <param name="rows">The rows.</param>
        /// <param name="columns">The columns.</param>
        /// <param name="width">The width.</param>
        /// <param name="useTableRowHeader">if set to <c>true</c> [use table row header].</param>
        /// <param name="useBorder">The useBorder.</param>
        /// <returns></returns>
        public static Table CreateTextDocumentTable(
            AODL.Document.TextDocuments.TextDocument document,
            string tableName,
            string styleName,
            int rows,
            int columns,
            double width,
            bool useTableRowHeader,
            bool useBorder)
        {
            string tableCnt = document.DocumentMetadata.TableCount.ToString();
            Table  table    = new Table(document, tableName, styleName);

            table.TableStyle.TableProperties.Width = width.ToString().Replace(",", ".") + "cm";

            for (int i = 0; i < columns; i++)
            {
                Column column = new Column(table, "co" + tableCnt + i.ToString());
                column.ColumnStyle.ColumnProperties.Width = GetColumnCellWidth(columns, width);
                table.ColumnCollection.Add(column);
            }

            if (useTableRowHeader)
            {
                rows--;
                RowHeader rowHeader = new RowHeader(table);
                Row       row       = new Row(table, "roh1" + tableCnt);
                for (int i = 0; i < columns; i++)
                {
                    Cell cell = new Cell(table.Document, "rohce" + tableCnt + i.ToString());
                    if (useBorder)
                    {
                        cell.CellStyle.CellProperties.Border = Border.NormalSolid;
                    }
                    row.Cells.Add(cell);
                }
                rowHeader.RowCollection.Add(row);
                table.RowHeader = rowHeader;
            }

            for (int ir = 0; ir < rows; ir++)
            {
                Row row = new Row(table, "ro" + tableCnt + ir.ToString());

                for (int ic = 0; ic < columns; ic++)
                {
                    Cell cell = new Cell(table.Document, "ce" + tableCnt + ir.ToString() + ic.ToString());
                    if (useBorder)
                    {
                        cell.CellStyle.CellProperties.Border = Border.NormalSolid;
                    }
                    row.Cells.Add(cell);
                }

                table.Rows.Add(row);
            }

            return(table);
        }
コード例 #4
0
        private void SaveInODF()
        {
            using (AODL.Document.TextDocuments.TextDocument doc = new AODL.Document.TextDocuments.TextDocument())
            {
                if (_isNew)
                {
                    doc.New();
                }
                else
                {
                    doc.Load(Filename);
                }

                try
                {
                    int imageCount = 1; //This is a counter for setting the image number.
                    foreach (KeyValuePair <int, Paragraph> paragraph in Paragraphs)
                    {
                        //If this is an image we also need to pass the MainpArt as this is needed to generate the image part
                        Picture img   = paragraph.Value as Picture;
                        Table   table = paragraph.Value as Table;
                        List    list  = paragraph.Value as List;
                        if (img != null)
                        {
                            foreach (var p in img.GetODFParagraph(doc, paragraph.Key, ref imageCount))
                            {
                                doc.Content.Add(p);
                            }
                        }
                        else if (table != null)
                        {
                            //Add table to the document
                            doc.Content.Add(table.GetODFTable(doc));
                        }
                        else if (list != null)
                        {
                            //Add the list.
                            doc.Content.Add(list.GetODFList(doc));
                        }
                        else
                        {
                            //Add the text paragraph(s)
                            foreach (var p in paragraph.Value.GetODFParagraph(doc))
                            {
                                doc.Content.Add(p);
                            }
                        }
                    }

                    /* Save the results and close */
                    doc.SaveTo(Filename);
                }
                catch (Exception ex)
                {
                    throw new FileLoadException("An error occured when saving the document: " + ex.Message, Filename, ex);
                }
            }
        }
コード例 #5
0
 public AODL.Document.TextDocuments.TextDocument Convert(FlowDocument flowdoc)
 {
     AODL.Document.TextDocuments.TextDocument textdoc = new AODL.Document.TextDocuments.TextDocument();
     textdoc.New();
     foreach (Paragraph p in flowdoc.Blocks)
     {
         AODL.Document.Content.Text.Paragraph par = new AODL.Document.Content.Text.Paragraph(textdoc);
         TextRange t = new TextRange(p.ElementStart, p.ElementEnd);
         par.TextContent.Add(new AODL.Document.Content.Text.SimpleText(textdoc, t.Text));
     }
     return(textdoc);
 }
コード例 #6
0
        public FlowDocument Convert(string filename)
        {
            AODL.Document.TextDocuments.TextDocument opendocument = new AODL.Document.TextDocuments.TextDocument();
            opendocument.Load(filename);
            FlowDocument flowdocument = new FlowDocument();

            foreach (AODL.Document.Content.Text.Paragraph p in opendocument.Content)
            {
                Paragraph par = new Paragraph();
                foreach (AODL.Document.Content.Text.SimpleText t in p.TextContent)
                {
                    //TODO: (20xx.xx) Add OpenDocument Format support
                    par.ElementStart.InsertTextInRun(t.Text);
                }
                flowdocument.Blocks.Add(par);
            }
            return(flowdocument);
        }
コード例 #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 IContent GetODFTable(AODL.Document.TextDocuments.TextDocument doc)
        {
            //Get the max columns in a row .
            var colCount = 0;

            foreach (var row in _rows)
            {
                if (row.RowColcount > colCount)
                {
                    colCount = row.RowColcount;
                }
            }

            //Create a table for a text document using the TableBuilder
            var table = TableBuilder.CreateTextDocumentTable(
                doc,
                Text,
                "table1",
                RowCount + 1,
                colCount,
                16.99,
                Col.Colcount > 0,
                false);

            //Fill the cells
            foreach (var row in Row)
            {
                //Pass the current row in to Row object.
                //This seems the easiest way to fill them.
                //row.GetODF(table.Rows[Row.IndexOf(row)]);
            }

            //Fill the header
            if (Col != null && Col.Colcount > 0 && table.RowHeader.RowCollection.Count > 0)
            {
                Col.GetODF(table.RowHeader.RowCollection[0]);
            }

            return(table);
        }
コード例 #8
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
            });
        }
コード例 #9
0
        /// <summary>
        /// Gets the HTML style.
        /// </summary>
        /// <param name="headingname">The headingname.</param>
        /// <returns>The css style element</returns>
        private string GetHtmlStyle(string headingname)
        {
            try
            {
                string style    = "style=\"margin-left: 0.5cm; margin-top: 0.5cm; margin-bottom: 0.5cm; ";
                string fontname = "";
                string fontsize = "";
                string bold     = "";
                string italic   = "";

                if (this.Document is AODL.Document.TextDocuments.TextDocument)
                {
                    AODL.Document.TextDocuments.TextDocument doc = (AODL.Document.TextDocuments.TextDocument) this.Document;
                    XmlNode stylenode = doc.DocumentStyles.Styles.SelectSingleNode("//style:style[@style:name='" + headingname + "']",
                                                                                   this.Document.NamespaceManager);
                    XmlNode propertynode = null;

                    if (stylenode != null)
                    {
                        propertynode = stylenode.SelectSingleNode("style:text-properties", this.Document.NamespaceManager);
                    }

                    if (propertynode != null)
                    {
                        XmlNode attribute = propertynode.SelectSingleNode("@fo:font-name", this.Document.NamespaceManager);
                        if (attribute != null)
                        {
                            fontname = "font-family:" + attribute.InnerText + "; ";
                        }

                        attribute = propertynode.SelectSingleNode("@fo:font-size", this.Document.NamespaceManager);
                        if (attribute != null)
                        {
                            fontsize = "font-size:" + attribute.InnerText + "; ";
                        }

                        if (propertynode.OuterXml.IndexOf("bold") != -1)
                        {
                            bold = "font-weight: bold; ";
                        }

                        if (propertynode.OuterXml.IndexOf("italic") != -1)
                        {
                            italic = "font-style: italic; ";
                        }
                    }

                    if (fontname.Length > 0)
                    {
                        style += fontname;
                    }
                    if (fontsize.Length > 0)
                    {
                        style += fontsize;
                    }
                    if (bold.Length > 0)
                    {
                        style += bold;
                    }
                    if (italic.Length > 0)
                    {
                        style += italic;
                    }

                    if (style.EndsWith(" "))
                    {
                        style += "\"";
                    }
                    else
                    {
                        style = "";
                    }

                    return(style);
                }
            }
            catch (Exception ex)
            {
                string exs = ex.Message;
            }

            return("");
        }
コード例 #10
0
        /// <summary>
        /// Gets the picture in OOXMLFormat
        /// </summary>
        /// <param name="doc">The document to add the image to</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 <AODL.Document.Content.IContent> GetODFParagraph(AODL.Document.TextDocuments.TextDocument doc, int index, ref int imageCount)
        {
            //Create a string with the filename to use.
            //This is the given filename or a temp file if there is only an image.
            string tempFileName = _filePath;

            if (string.IsNullOrEmpty(tempFileName))
            {
                //If there is only an image and not a filepath create a tempfile.
                string dir = string.Format("{0}\\DocumentGenerator", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData));
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
                tempFileName = string.Format("{0}\\Image{1}.jpg", dir, index);
                _image.Save(tempFileName);
            }

            //Create the main paragraph.
            AODL.Document.Content.Text.Paragraph p = ParagraphBuilder.CreateStandardTextParagraph(doc);
            if (!string.IsNullOrEmpty(_text))
            {
                //Draw the text box for the label
                var drawTextBox  = new DrawTextBox(doc);
                var frameTextBox = new AODL.Document.Content.Draw.Frame(doc, "fr_txt_box")
                {
                    DrawName = "fr_txt_box", ZIndex = "0"
                };
                //Create the paragraph for the image
                var pInner = ParagraphBuilder.CreateStandardTextParagraph(doc);
                pInner.StyleName = "Illustration";
                //Create the image frame
                var frame = new AODL.Document.Content.Draw.Frame(doc, "frame1", string.Format("graphic{0}", index), tempFileName)
                {
                    ZIndex = "1"
                };
                //Add the frame.
                pInner.Content.Add(frame);
                //Add the title
                pInner.TextContent.Add(new SimpleText(doc, _text));
                //Draw the text and image in the box.
                drawTextBox.Content.Add(pInner);
                frameTextBox.SvgWidth = frame.SvgWidth;
                drawTextBox.MinWidth  = frame.SvgWidth;
                drawTextBox.MinHeight = frame.SvgHeight;
                frameTextBox.Content.Add(drawTextBox);
                p.Content.Add(frameTextBox);
            }
            else
            {
                //Create a frame with the image.
                var frame = new AODL.Document.Content.Draw.Frame(doc, "Frame1", string.Format("graphic{0}", index), tempFileName);
                p.Content.Add(frame);
            }

            //Finally delete image file if it is a temp file.
            //if (tempFileName != _filePath) File.Delete(tempFileName);

            return(new List <AODL.Document.Content.IContent> {
                p
            });
        }