static void CreateDocumentTextFlow(C1WordDocument word)
        {
            // load long string from resource file
            string text = Strings.ResourceNotFound;

            using (var sr = new StreamReader(typeof(BasicTextPage).GetTypeInfo().Assembly.GetManifestResourceStream("WordSamples.Resources.flow.txt")))
            {
                text = sr.ReadToEnd();
            }

            // content rectangle
            Rect rcPage = WordUtils.PageRectangle(word);

            // create two columns for the text
            var columnWidth = (float)(rcPage.Width - 30) / 2;

            word.MainSection.Columns.Clear();
            word.MainSection.Columns.Add(new RtfColumn(columnWidth));
            word.MainSection.Columns.Add(new RtfColumn(columnWidth));

            // add title
            Font titleFont = new Font("Tahoma", 14, RtfFontStyle.Bold);
            Font bodyFont  = new Font("Tahoma", 11);

            word.AddParagraph(Strings.MsWordFormats, titleFont, Colors.DarkOliveGreen, RtfHorizontalAlignment.Center);
            word.AddParagraph(string.Empty);

            // first paragraph about C1Word object model
            var paragraph = word.GetParagraph(string.Empty, bodyFont);
            var hyperlink = new RtfHyperlink(Strings.WordSamplesWordLink, Colors.Blue, RtfUnderlineStyle.Single);

            hyperlink.Add(new RtfString(Strings.WordSamplesWordTitle));
            paragraph.Add(hyperlink);
            word.Add(paragraph);
            word.AddParagraph(string.Empty);

            // render string spanning columns and pages
            foreach (var part in text.Split(new string[] { Environment.NewLine }, StringSplitOptions.None))
            {
                word.AddParagraph(part, bodyFont, Colors.Black, RtfHorizontalAlignment.Justify);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Shows how to position and align text
        /// </summary>
        static void CreateDocumentText(C1WordDocument word)
        {
            // use landscape for more impact
            word.Landscape = true;

            // show some text
            var text = Strings.DocumentBasicText;
            var font = new Font("Segoe UI Light", 14, RtfFontStyle.Regular);

            // add paragraph
            word.AddParagraph(text, font, Colors.MidnightBlue, RtfHorizontalAlignment.Justify);
            var paragraph = (RtfParagraph)word.Current;

            paragraph.LeftBorderColor  = Colors.Blue;
            paragraph.LeftBorderStyle  = RtfBorderStyle.Emboss;
            paragraph.LeftBorderWidth  = 1f;
            paragraph.TopBorderColor   = Colors.Blue;
            paragraph.TopBorderStyle   = RtfBorderStyle.Emboss;
            paragraph.TopBorderWidth   = 2f;
            paragraph.RightBorderColor = Colors.Purple;
            paragraph.RightBorderStyle = RtfBorderStyle.DotDash;
            paragraph.RightBorderWidth = 5f;

            // next show some text
            text = Strings.DocumentBasicText2;
            word.AddParagraph(text, font, Colors.Black, RtfHorizontalAlignment.Justify);
            paragraph = (RtfParagraph)word.Current;
            paragraph.LeftBorderColor   = Colors.DeepPink;
            paragraph.LeftBorderStyle   = RtfBorderStyle.DashDotStroked;
            paragraph.LeftBorderWidth   = 4f;
            paragraph.RightBorderColor  = Colors.Chocolate;
            paragraph.RightBorderStyle  = RtfBorderStyle.Single;
            paragraph.RightBorderWidth  = 2f;
            paragraph.BottomBorderColor = Colors.DarkRed;
            paragraph.BottomBorderStyle = RtfBorderStyle.Dashed;
            paragraph.BottomBorderWidth = 3f;

            // RTF/Word formats
            var titleFont = new Font("Segoe UI Light", 48, RtfFontStyle.Bold);

            paragraph = word.GetParagraph(string.Empty, titleFont);
            var rs = new RtfString("R", titleFont);

            rs.ForeColor = Colors.Red;
            paragraph.Add(rs);
            rs           = new RtfString("T", titleFont);
            rs.ForeColor = Colors.DarkGreen;
            paragraph.Add(rs);
            rs           = new RtfString("F", titleFont);
            rs.ForeColor = Colors.BlueViolet;
            paragraph.Add(rs);
            rs           = new RtfString(" / ", titleFont);
            rs.ForeColor = Colors.Coral;
            paragraph.Add(rs);
            titleFont    = new Font("Segoe UI Light", 48, RtfFontStyle.Bold | RtfFontStyle.Italic);
            rs           = new RtfString("Word", titleFont);
            rs.ForeColor = Colors.DarkSeaGreen;
            paragraph.Add(rs);
            word.Add(paragraph);
            var tableFont = new Font("Segoe UI Light", 16, RtfFontStyle.Regular);

            word.AddParagraph(string.Empty, tableFont, Colors.Black);

            // add table
            int      rows  = 4;
            int      cols  = 3;
            RtfTable table = new RtfTable(rows, cols);

            word.Add(table);
            table.Rows[0].Cells[0].SetMerged(1, 2);
            for (int row = 0; row < rows; row++)
            {
                if (row == 0)
                {
                    table.Rows[row].Height = 50;
                }
                for (int col = 0; col < cols; col++)
                {
                    if (row == 0 && col == 0)
                    {
                        // table header
                        text = Strings.DocumentBasicMergedCell;
                        table.Rows[row].Cells[col].Alignment   = ContentAlignment.MiddleCenter;
                        table.Rows[row].Cells[col].BackFilling = Colors.LightPink;
                    }
                    else
                    {
                        // table cell
                        text = string.Format("table cell {0}:{1}.", row, col);
                        table.Rows[row].Cells[col].BackFilling = Colors.LightYellow;
                    }
                    table.Rows[row].Cells[col].Content.Add(new RtfString(text));
                    table.Rows[row].Cells[col].BottomBorderWidth = 2;
                    table.Rows[row].Cells[col].TopBorderWidth    = 2;
                    table.Rows[row].Cells[col].LeftBorderWidth   = 2;
                    table.Rows[row].Cells[col].RightBorderWidth  = 2;
                    if (col == cols - 1)
                    {
                        table.Rows[row].Cells[col].Alignment = ContentAlignment.BottomRight;
                    }
                }
            }
        }