Example #1
0
		private RadDocument CreateDocument()
		{
			RadDocument document = new RadDocument();
			Section section = new Section();
			Paragraph paragraph = new Paragraph();

			MemoryStream ms = new MemoryStream();
			radChart.ExportToImage(ms, new PngBitmapEncoder());

			double imageWidth = radChart.ActualWidth;
			double imageHeight = radChart.ActualHeight;

			if (imageWidth > 625)
			{
				imageWidth = 625;
				imageHeight = radChart.ActualHeight * imageWidth / radChart.ActualWidth;
			}

			ImageInline image = new ImageInline(ms, new Size(imageWidth, imageHeight), "png");

			paragraph.Inlines.Add(image);
			section.Blocks.Add(paragraph);
			document.Sections.Add(section);

			ms.Close();

			return document;
		}
Example #2
0
        private void ExportToHtml()
        {
            RadDocument document = GenerateRadDocument();
            var         provider = new HtmlFormatProvider();

            ShowPrintPreviewDialog(document, provider);
        }
        private Footer CreateFooter()
        {
            RadDocument       footerDocument = new RadDocument();
            RadDocumentEditor editor         = new RadDocumentEditor(footerDocument);

            editor.InsertTable(1, 2);
            editor.ChangeStyleName(RadDocumentDefaultStyles.DefaultNormalTableStyleName);

            editor.Document.Selection.SelectAll();

            editor.ChangeFontFamily(new FontFamily("Arial"));
            editor.ChangeForeColor(Color.FromRgb(29, 192, 34));
            editor.ChangeFontSize(Unit.PointToDip(10));

            editor.Document.Selection.Clear();

            editor.Insert("Copyright © 2002-2015 Telerik. All rights reserved.");

            var table = editor.Document.EnumerateChildrenOfType <Table>().FirstOrDefault();

            editor.Document.CaretPosition.MoveToStartOfDocumentElement(table.Rows.First.Cells.Last);
            table.Grid.Columns.Last().PreferredWidth = new TableWidthUnit(20);

            PageField field = new PageField();

            editor.InsertField(field, FieldDisplayMode.Result);
            editor.ChangeParagraphTextAlignment(RadTextAlignment.Right);

            Footer footer = new Footer()
            {
                Body = footerDocument
            };

            return(footer);
        }
Example #4
0
        private RadDocument CreateDocument()
        {
            RadDocument document  = new RadDocument();
            Section     section   = new Section();
            Paragraph   paragraph = new Paragraph();

            MemoryStream ms = new MemoryStream();

            radChart.ExportToImage(ms, new PngBitmapEncoder());

            double imageWidth  = radChart.ActualWidth;
            double imageHeight = radChart.ActualHeight;

            if (imageWidth > 625)
            {
                imageWidth  = 625;
                imageHeight = radChart.ActualHeight * imageWidth / radChart.ActualWidth;
            }

            ImageInline image = new ImageInline(ms, new Size(imageWidth, imageHeight), "png");

            paragraph.Inlines.Add(image);
            section.Blocks.Add(paragraph);
            document.Sections.Add(section);

            ms.Close();

            return(document);
        }
Example #5
0
        private static RadDocument CreateDocument(int seed)
        {
            var document   = new RadDocument();
            var section    = new Section();
            var paragraph1 = new Paragraph();

            section.Blocks.Add(paragraph1);
            var paragraph2 = new Paragraph();

            paragraph2.TextAlignment = RadTextAlignment.Center;
            var span1 = new Span("Thank you for choosing Telerik");

            paragraph2.Inlines.Add(span1);
            var span2 = new Span();

            span2.Text       = " RadRichTextBox!";
            span2.FontWeight = FontWeights.Bold;
            paragraph2.Inlines.Add(span2);
            section.Blocks.Add(paragraph2);
            var rand       = new Random(seed);
            var paragraph3 = new Paragraph();
            var span3      = new Span(content[rand.Next(0, 6)]);

            paragraph3.Inlines.Add(span3);
            section.Blocks.Add(paragraph3);
            section.Blocks.Add(new Paragraph());
            document.Sections.Add(section);

            return(document);
        }
        private Tuple <DocumentPosition, string> GetPreviousWord(RadDocument radDocument, DocumentPosition caretPosition)
        {
            DocumentPosition pos = new DocumentPosition(richTextBox.Document);

            pos.MoveToPosition(caretPosition);
            pos.MoveToPreviousWordStart();
            radDocument.Selection.SetSelectionStart(pos);
            radDocument.Selection.AddSelectionEnd(caretPosition);



            // var text = pos.GetCurrentInlineBox().Text;
            string text = radDocument.Selection.GetSelectedText();; // pos.GetCurrentWord();

            if (text.Contains("_"))
            {
                pos.MoveToPreviousWordStart();
                radDocument.Selection.SetSelectionStart(pos);
                radDocument.Selection.AddSelectionEnd(caretPosition);
                text = radDocument.Selection.GetSelectedText();
            }
            if (text != null && text != "" && text != ".")
            {
                if (text.EndsWith("."))
                {
                    text = text.Substring(0, text.Length - 1);
                }
            }
            var previousOfMainCaret = new DocumentPosition(pos);

            radDocument.Selection.Clear();
            return(new Tuple <DocumentPosition, string>(previousOfMainCaret, text));
            //////var word = GetText(previousOfMainCaret, caretPosition);// pos.Get
            //////return new Tuple<DocumentPosition, string>(previousOfMainCaret, word);
        }
        private void CreateShowDocument()
        {
            var document = new RadDocument();

            document.LayoutMode = DocumentLayoutMode.Paged;

            RadDocumentEditor editor = new RadDocumentEditor(document);

            editor.Insert("Text Before Text Inside Text After");

            DocumentPosition rangeStartPosition = new DocumentPosition(document);

            rangeStartPosition.MoveToNextWordStart();
            rangeStartPosition.MoveToNextWordStart();

            DocumentPosition rangeEndPosition = new DocumentPosition(rangeStartPosition);

            rangeEndPosition.MoveToNextWordStart();
            rangeEndPosition.MoveToCurrentWordEnd();

            document.Selection.SetSelectionStart(rangeStartPosition);
            document.Selection.AddSelectionEnd(rangeEndPosition);

            editor.InsertAnnotationRange(new CustomRangeStart(), new CustomRangeEnd());

            this.radRichTextBox.Document = document;

            UpdateTextBoxText();
        }
Example #8
0
        private static RadDocument CreateDocument()
        {
            var doc = new RadDocument();


            return(doc);
        }
Example #9
0
        private void ShowArticle()
        {
            StackPanel     sp  = new StackPanel();
            RadRichTextBox rtb = new RadRichTextBox();

            var reqItem = RequirementViewModelLocator.GetRequirementVM().GetRequirement(SelectedItem.ID, null);
            XamlFormatProvider provider = new XamlFormatProvider();
            RadDocument        document;

            if (reqItem.Content != null)
            {
                document = provider.Import(reqItem.Content);
            }
            else
            {
                document = new RadDocument();
            }
            rtb.Document            = document;
            rtb.Document.LayoutMode = DocumentLayoutMode.Flow;
            sp.Children.Add(rtb);

            var window = new RadWindow
            {
                WindowStartupLocation = WindowStartupLocation.CenterOwner,
                Header  = SelectedItem.ArticleHeader,
                Content = sp,
                Width   = 700,
                Height  = 500,
            };

            window.Show();
        }
Example #10
0
        private static RadDocument CreateHeader(params string[] titles)
        {
            RadDocument document = new RadDocument();

            Paragraph titleParagraph = new Paragraph();
            titleParagraph.TextAlignment = RadTextAlignment.Center;
            Span titleSpan = new Span(titles.First());
            titleParagraph.Inlines.Add(titleSpan);

            document.Sections.Add(new Section());
            document.Sections.First.Blocks.Add(titleParagraph);

            if (titles.Count() > 1)
            {
                for (int i = 1; i < titles.Count(); i++)
                {
                    var paragraph = new Paragraph();
                    paragraph.TextAlignment = RadTextAlignment.Center;
                    Span span = new Span(titles[i]);
                    paragraph.Inlines.Add(span);
                    document.Sections.First.Blocks.Add(paragraph);
                }
            }

            Paragraph emptyParagraph = new Paragraph();
            document.Sections.First.Blocks.Add(emptyParagraph);

            return document;
        }
Example #11
0
        private void RadRichTextBox_CommandExecuting(object sender, CommandExecutingEventArgs e)
        {
            if (e.Command is SaveCommand)
            {
                e.Cancel = true;
                SaveDocument(); // A custom logic for saving document so you can change the properties of the Save File dialog.
            }

            if (e.Command is PasteCommand)
            {
                // Altering the PasteCommand to ensure only plain text is pasted in RadRichTextBox.
                // Obtain the content from the clipboard.
                RadDocument documentFromClipboard = ClipboardEx.GetDocument().ToDocument();

                TxtFormatProvider provider = new TxtFormatProvider();
                // Convert it to plain text.
                string plainText = provider.Export(documentFromClipboard);

                // Create a RadDocument instance from the plain text.
                RadDocument documentToInsert = provider.Import(plainText);
                // Set this document as a content to the clipboard.
                ClipboardEx.SetDocument(new DocumentFragment(documentToInsert));
            }

            if (e.Command is InsertTableCommand)
            {
                // Disable the possibility to insert tables into the document.
                MessageBox.Show("Inserting tables is not allowed.");
                e.Cancel = true;
            }
        }
Example #12
0
        private void OpenDocument()
        {
            using (OpenFileDialog openDialog = new OpenFileDialog())
            {
                openDialog.Filter = "Word Documents (*.docx)|*.docx|Web Pages (*.htm,*.html)|*.htm;*.html|Rich Text Format (*.rtf)|*.rtf|Text Files (*.txt)|*.txt|XAML Files (*.xaml)|*.xaml";

                if (openDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    string extension = Path.GetExtension(openDialog.SafeFileName).ToLower();

                    IDocumentFormatProvider provider = GetProviderByExtension(extension);

                    if (provider == null)
                    {
                        RadMessageBox.Show("Unable to find format provider for extension " + extension, "Error");
                        return;
                    }

                    using (Stream stream = openDialog.OpenFile())
                    {
                        RadDocument document = provider.Import(stream);
                        this.DetachDocument(this.radRichTextBox1.Document);
                        this.radRichTextBox1.Document = document;
                        this.AttachDocument(document);
                        document.LayoutMode = DocumentLayoutMode.Paged;
                    }
                }

                this.radRichTextBox1.Focus();
            }
        }
Example #13
0
        private static RadDocument CreateHeader(params string[] titles)
        {
            RadDocument document = new RadDocument();

            Paragraph titleParagraph = new Paragraph();

            titleParagraph.TextAlignment = RadTextAlignment.Center;
            Span titleSpan = new Span(titles.First());

            titleParagraph.Inlines.Add(titleSpan);

            document.Sections.Add(new Section());
            document.Sections.First.Blocks.Add(titleParagraph);

            if (titles.Count() > 1)
            {
                for (int i = 1; i < titles.Count(); i++)
                {
                    var paragraph = new Paragraph();
                    paragraph.TextAlignment = RadTextAlignment.Center;
                    Span span = new Span(titles[i]);
                    paragraph.Inlines.Add(span);
                    document.Sections.First.Blocks.Add(paragraph);
                }
            }

            Paragraph emptyParagraph = new Paragraph();

            document.Sections.First.Blocks.Add(emptyParagraph);

            return(document);
        }
Example #14
0
        private void CreateShowDocument()
        {
            var document = new RadDocument();
            document.LayoutMode = DocumentLayoutMode.Paged;

            RadDocumentEditor editor = new RadDocumentEditor(document);
            editor.Insert("Text Before Text Inside Text After");

            DocumentPosition rangeStartPosition = new DocumentPosition(document);
            rangeStartPosition.MoveToNextWordStart();
            rangeStartPosition.MoveToNextWordStart();

            DocumentPosition rangeEndPosition = new DocumentPosition(rangeStartPosition);
            rangeEndPosition.MoveToNextWordStart();
            rangeEndPosition.MoveToCurrentWordEnd();

            document.Selection.SetSelectionStart(rangeStartPosition);
            document.Selection.AddSelectionEnd(rangeEndPosition);

            editor.InsertAnnotationRange(new CustomRangeStart(), new CustomRangeEnd());

            this.radRichTextBox.Document = document;

            UpdateTextBoxText();
        }
Example #15
0
 private void SetupNewDocument(RadDocument document)
 {
     document.LayoutMode = DocumentLayoutMode.Paged;
     document.ParagraphDefaultSpacingAfter = 10;
     document.PageViewMargin           = new SizeF(10, 10);
     document.SectionDefaultPageMargin = new Padding(95);
 }
Example #16
0
        public static void Export(RadDocument document, params string[] titles)
        {
            var filePath = Path.GetTempFileName().Replace(".tmp", ".pdf");

            var documentHeader = CreateHeader(titles);

            document.Sections.First.Headers.Default = new Header()
            {
                Body = documentHeader
            };

            if (document != null)
            {
                document.LayoutMode = DocumentLayoutMode.Paged;
                document.Measure(RadDocument.MAX_DOCUMENT_SIZE);
                document.SectionDefaultPageMargin = new Padding(40, 60, 30, 30);

                document.Arrange(new RectangleF(PointF.Empty, document.DesiredSize));

                IDocumentFormatProvider provider = new PdfFormatProvider();

                using (Stream stream = new FileStream(filePath, FileMode.Create))
                {
                    provider.Export(document, stream);
                }
            }

            Process.Start(filePath);
        }
Example #17
0
        private void Document_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            RadDocument document = sender as RadDocument;

            this.radBtnPrintLayout.ToggleState = document.LayoutMode == DocumentLayoutMode.Paged ? ToggleState.On : ToggleState.Off;
            this.radBtnWebLayout.ToggleState   = document.LayoutMode == DocumentLayoutMode.Flow ? ToggleState.On : ToggleState.Off;
        }
Example #18
0
        private RadDocument LoadDocumentToInsert()
        {
            RadDocument document = null;

            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = "Word Documents (*.docx)|*.docx|All Files (*.*)|*.*";

            if (ofd.ShowDialog() == true)
            {
                string extension;
#if SILVERLIGHT
                extension = ofd.File.Extension.ToLower();
#else
                extension = Path.GetExtension(ofd.SafeFileName).ToLower();
#endif

                IDocumentFormatProvider provider = DocumentFormatProvidersManager.GetProviderByExtension(extension);

                Stream stream;
#if SILVERLIGHT
                stream = ofd.File.OpenRead();
#else
                stream = ofd.OpenFile();
#endif
                using (stream)
                {
                    document = provider.Import(stream);
                }
            }

            return(document);
        }
Example #19
0
        public static void Export(RadDocument document, params string[] titles)
        {
            var filePath = Path.GetTempFileName().Replace(".tmp", ".pdf");

            var documentHeader = CreateHeader(titles);
            document.Sections.First.Headers.Default = new Header() { Body = documentHeader };

            if (document != null)
            {
                document.LayoutMode = DocumentLayoutMode.Paged;
                document.Measure(RadDocument.MAX_DOCUMENT_SIZE);
                document.SectionDefaultPageMargin = new Padding(40, 60, 30, 30);

                document.Arrange(new RectangleF(PointF.Empty, document.DesiredSize));

                IDocumentFormatProvider provider = new PdfFormatProvider();

                using (Stream stream = new FileStream(filePath, FileMode.Create))
                {
                    provider.Export(document, stream);
                }
            }

            Process.Start(filePath);
        }
        public PrintPreview(RadDocument document, IDocumentFormatProvider provider)
        {
            InitializeComponent();
            this.document = document;
            this.provider = provider;

            this.RichTextBox.Document = this.document;
        }
        public MainWindow()
        {
            InitializeComponent();

            RadDocument document = CreateDocument();

            this.radRichTextBox.Document = document;
        }
Example #22
0
        private void LoadSampleDocument()
        {
            Stream             stream   = Application.GetResourceStream(new Uri(SampleDocumentPath, UriKind.RelativeOrAbsolute)).Stream;
            DocxFormatProvider provider = new DocxFormatProvider();
            RadDocument        document = provider.Import(stream);

            this.radRichTextBox.Document = document;
        }
Example #23
0
        private static void CopySectionProperties(RadDocument fromDocument, RadDocument toDocument)
        {
            CopyHeaderAndFooter(fromDocument, toDocument);

            toDocument.Sections.Last.PageOrientation = fromDocument.Sections.Last.PageOrientation;
            toDocument.Sections.Last.PageSize        = fromDocument.Sections.Last.PageSize;
            toDocument.Sections.Last.PageMargin      = fromDocument.Sections.Last.PageMargin;
        }
        public PrintPreview(RadDocument document, IDocumentFormatProvider provider)
        {
            InitializeComponent();
            this.document = document;
            this.provider = provider;

            this.RichTextBox.Document = this.document;
        }
Example #25
0
        /// <summary>
        /// Method to Merge Multiple RadDocuments
        /// </summary>
        /// <param name="tables">Array of type RadDocuments</param>
        /// <returns>Merged Documents</returns>
        private RadDocument MergeDocuments(List <Table> tables)
        {
            RadDocument mergedDocument = new RadDocument();

            mergedDocument.Sections.Add(GetSection(tables, 0, 4));
            mergedDocument.Sections.Add(GetSection(tables, 4, tables.Count));
            return(mergedDocument);
        }
Example #26
0
        private static void CopySectionProperties(RadDocument fromDocument, RadDocument toDocument)
        {
            CopyHeaderAndFooter(fromDocument, toDocument);

            toDocument.Sections.Last.PageOrientation = fromDocument.Sections.Last.PageOrientation;
            toDocument.Sections.Last.PageSize = fromDocument.Sections.Last.PageSize;
            toDocument.Sections.Last.PageMargin = fromDocument.Sections.Last.PageMargin;
        }
        private void InsertCustomFieldInFooter()
        {
            RadDocument document = new RadDocument();
            RadDocumentEditor editor = new RadDocumentEditor(document);

            Footer footer = associatedRichTextBox.Document.Sections.First.Footers.Default;
            footer.Body = document;

            editor.InsertField(new CustomField(), FieldDisplayMode.Result);
        }
Example #28
0
        void radRichTextBox_Loaded(object sender, RoutedEventArgs e)
        {
            RadDocument document   = new RadDocument();
            string      randomText = @"On the Insert tab, the galleries include items that are designed to coordinate with the overall look of your document. You can use these galleries to insert tables, headers, footers, lists, cover pages, and other document building blocks. When you create pictures, charts, or diagrams, they also coordinate with your current document look";

            document.Insert(randomText, document.StyleRepository[RadDocumentDefaultStyles.NormalStyleName]);

            this.radRichTextBox.Document = (RadDocument)document.CreateDeepCopy();
            this.radRichTextBox.Document.Sections.First.Headers.Default.Body = document;
        }
Example #29
0
        void EmailBodyContent_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            var mimePartVm = e.NewValue as MimePartVm;

            if (mimePartVm != null)
            {
                RadDocument content = null;
                var         plain   = true;
                if (!String.IsNullOrEmpty(mimePartVm.MIMEpart.ContentSubtype))
                {
                    if (mimePartVm.MIMEpart.ContentSubtype.Equals("html"))
                    {
                        content = new HtmlFormatProvider().Import(mimePartVm.RawContent);
                        plain   = false;
                    }
                    else if (mimePartVm.MIMEpart.ContentSubtype.Equals("rtf"))
                    {
                        content = new RtfFormatProvider().Import(mimePartVm.RawContent);
                        plain   = false;
                    }

                    /* else if (mimePartVm.Data.ContentSubtype.Equals("pdf"))
                     * {
                     *   content = new PdfFormatProvider().Import(mimePartVm.RawContent);
                     * }*/
                    else
                    {
                        content = new TxtFormatProvider().Import(mimePartVm.RawContent);
                        //content = new XamlFormatProvider().Import(mimePartVm.RawContent);
                    }
                }
                else
                {
                    // content = new XamlFormatProvider().Import(mimePartVm.RawContent);
                    //TxtFormatProvider formatProvider = new TxtFormatProvider();
                    content = new TxtFormatProvider().Import(mimePartVm.RawContent);
                    //content = new TxtDataProvider(mimePartVm.RawContent);
                }

                if (plain)
                {
                    foreach (var span in content.EnumerateChildrenOfType <Span>())
                    {
                        span.FontSize = 12;
                    }
                }

                content.LineSpacing = 1.1;
                content.ParagraphDefaultSpacingAfter  = 0;
                content.ParagraphDefaultSpacingBefore = 0;

                this.ContentTextBox.LineBreakingRuleLanguage = LineBreakingRuleLanguage.None;
                this.ContentTextBox.Document = content;
            }
        }
Example #30
0
        private void InsertCustomFieldInHeader()
        {
            RadDocument       document = new RadDocument();
            RadDocumentEditor editor   = new RadDocumentEditor(document);

            Header header = associatedRichTextBox.Document.Sections.First.Headers.Default;

            header.Body = document;

            editor.InsertField(new CustomField(), FieldDisplayMode.Result);
        }
        private static RadDocument CreateDocument(RadGridView grid, PrintSettings settings)
        {
            RadDocument document = null;

            using (var stream = new MemoryStream())
            {
                EventHandler <GridViewElementExportingEventArgs> elementExporting = (s, e) =>
                {
                    if (e.Element == ExportElement.Table)
                    {
                        e.Attributes["border"] = "0";
                    }
                    else if (e.Element == ExportElement.HeaderRow)
                    {
                        if (settings.HeaderBackground != null)
                        {
                            e.Styles.Add("background-color", settings.HeaderBackground.ToString().Remove(1, 2));
                        }
                    }
                    else if (e.Element == ExportElement.GroupHeaderRow)
                    {
                        if (settings.GroupHeaderBackground != null)
                        {
                            e.Styles.Add("background-color", settings.GroupHeaderBackground.ToString().Remove(1, 2));
                        }
                    }
                    else if (e.Element == ExportElement.Row)
                    {
                        if (settings.RowBackground != null)
                        {
                            e.Styles.Add("background-color", settings.RowBackground.ToString().Remove(1, 2));
                        }
                    }
                };

                grid.ElementExporting += elementExporting;

                grid.Export(stream, new GridViewExportOptions()
                {
                    Format            = Telerik.Windows.Controls.ExportFormat.Html,
                    ShowColumnFooters = grid.ShowColumnFooters,
                    ShowColumnHeaders = grid.ShowColumnHeaders,
                    ShowGroupFooters  = grid.ShowGroupFooters
                });

                grid.ElementExporting -= elementExporting;

                stream.Position = 0;

                document = new HtmlFormatProvider().Import(stream);
            }

            return(document);
        }
Example #32
0
        private void OpenFile(object parameter)
        {
            RadOpenFileDialog ofd = new RadOpenFileDialog();

            string stringParameter = parameter as string;

            if (stringParameter != null && stringParameter.Contains("|"))
            {
                ofd.Filter = stringParameter;
            }
            else
            {
                string filter = string.Join("|", DocumentFormatProvidersManager.FormatProviders.Where(fp => fp.CanImport)
                                            .OrderBy(fp => fp.Name)
                                            .Select(fp => FileHelper.GetFilter(fp))
                                            .ToArray()) + "|All Files|*.*";
                ofd.Filter = filter;
            }

            if (ofd.ShowDialog() == true)
            {
                string extension;
                extension = Path.GetExtension(ofd.FileName).ToLower();

                IDocumentFormatProvider provider =
                    DocumentFormatProvidersManager.GetProviderByExtension(extension);

                if (provider == null)
                {
                    MessageBox.Show(LocalizationManager.GetString("Documents_OpenDocumentCommand_UnsupportedFileFormat"));
                    return;
                }

                try
                {
                    Stream stream;
                    stream = ofd.OpenFile();
                    using (stream)
                    {
                        RadDocument document = provider.Import(stream);
                        this.radRichTextBox.Document = document;
                        this.SetDocumentName(ofd.FileName);
                    }
                }
                catch (IOException)
                {
                    MessageBox.Show(LocalizationManager.GetString("Documents_OpenDocumentCommand_TheFileIsLocked"));
                }
                catch (Exception)
                {
                    MessageBox.Show(LocalizationManager.GetString("Documents_OpenDocumentCommand_TheFileCannotBeOpened"));
                }
            }
        }
Example #33
0
        void radRichTextBox_Loaded(object sender, RoutedEventArgs e)
        {
            RadDocument document = new RadDocument();
            string randomText = @"On the Insert tab, the galleries include items that are designed to coordinate with the overall look of your document. You can use these galleries to insert tables, headers, footers, lists, cover pages, and other document building blocks. When you create pictures, charts, or diagrams, they also coordinate with your current document look";

            RadDocumentEditor documentEditor = new RadDocumentEditor(document);
            documentEditor.Insert(randomText);

            this.radRichTextBox.Document = (RadDocument)document.CreateDeepCopy();
            this.radRichTextBox.Document.Sections.First.Headers.Default.Body = document;
        }
        public NewEmailForm(RadDocument rteContnt, string to, string cc, string subject)
        {
            InitializeComponent();

            Initialize();

            mailRichTextEditor.Document = rteContnt;
            toTextBoxControl.Text       = to;
            ccTextBoxControl.Text       = cc;
            subjectTextBoxControl.Text  = subject;
        }
        public Example()
        {
            InitializeComponent();

            using (Stream stream = Application.GetResourceStream(GetResourceUri(SampleDocumentPath)).Stream)
            {
                IDocumentFormatProvider xamlProvider = DocumentFormatProvidersManager.GetProviderByExtension(".xaml");
                this.radDocument = xamlProvider.Import(stream);
            }

            this.exampleWindow.RadDocument = this.radDocument;
        }
Example #36
0
        private int GetTotalPageCount()
        {
            RadDocument document    = this.EvaluationContext.MainDocument ?? this.Document;
            int         pageCounter = 0;

            foreach (Section section in document.Sections)
            {
                pageCounter += section.GetAssociatedLayoutBoxes().Count();
            }

            return(pageCounter);
        }
        private void CreateFragments()
        {
            RadDocument radDocument = this.radRichTextBox.Document;

            #region radrichtextbox-features-formatting-api_6
            DocumentFragment fragmentFromDocument = new DocumentFragment(radDocument);
            #endregion

            #region radrichtextbox-features-formatting-api_8
            DocumentFragment fragmentFromSelection = radDocument.Selection.CopySelectedDocumentElements();
            #endregion
        }
        public override void Export(RadDocument document, Stream output)
        {
            //export as HTML
            using (output)
            {
                htmlProvider.Export(document, output);
            }
            //using Aspose.HTML to convert html to markdown
            var documentap = new HTMLDocument(outPath + "\\hide.html");
            var path       = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

            documentap.Save(Path.GetFullPath(outPath + "\\MarkDownFile.md"), HTMLSaveFormat.Markdown);
        }
Example #39
0
        private static void CopySectionProperties(RadDocument fromDocument, RadDocument toDocument)
        {
            CopyHeaderAndFooter(fromDocument, toDocument);

            RadDocumentEditor documentEditor = new RadDocumentEditor(toDocument);
            documentEditor.Document.CaretPosition.MoveToLastPositionInDocument();

            documentEditor.ChangeSectionPageOrientation(fromDocument.Sections.Last.PageOrientation);
            documentEditor.ChangeSectionPageSize(fromDocument.Sections.Last.PageSize);
            documentEditor.ChangeSectionPageMargin(fromDocument.Sections.Last.PageMargin);
            documentEditor.ChangeSectionFooterBottomMargin(fromDocument.Sections.Last.FooterBottomMargin);
            documentEditor.ChangeSectionHeaderTopMargin(fromDocument.Sections.Last.HeaderTopMargin);
        }
Example #40
0
        public MainWindow()
        {
            InitializeComponent();

            using (Stream stream = Application.GetResourceStream(new Uri("MailMerge;component/SampleData/SampleData.xaml", UriKind.Relative)).Stream)
            {
                XamlFormatProvider provider = new XamlFormatProvider();
                RadDocument        document = provider.Import(stream);
                this.editor.Document = document;
            }

            this.editor.Document.MailMergeDataSource.ItemsSource = new ExamplesDataContext().Employees;
        }
        private void AddTagger(RadDocument document)
        {
            CodeLanguage vbCodeLanguage = new CodeLanguage("VB");

            RegexTagger vbRegexTagger = MainWindow.GetVbTagger();

            document.CodeFormatter.RegisterCodeLanguage(vbCodeLanguage, vbRegexTagger);

            StyleDefinition vbKeywordStyle = new StyleDefinition("vbKeywordStyle", StyleType.Character);
            vbKeywordStyle.SpanProperties.ForeColor = Colors.Orange;

            document.CodeFormatter.RegisterClassificationType(ClassificationTypes.Keyword, vbCodeLanguage, vbKeywordStyle);
        }
        private void LoadSampleXamlDocument()
        {
            if (this.XamlDocument == null)
            {
                Stream xamlStream = Application.GetResourceStream(
                    GetResourceUri(SyntaxHighlight.Example.XamlResource)).Stream;

                using (StreamReader reader = new StreamReader(xamlStream))
                {
                    this.XamlDocument = CreateFormattedDocument(reader.ReadToEnd(), ".xaml");
                }
            }

            this.Editor.Document = this.XamlDocument;
        }
 private static void SaveFile(SaveFileDialog dialog, IDocumentFormatProvider provider, RadDocument document)
 {
     var result = dialog.ShowDialog();
     if (result == true)
     {
         try
         {
             using (var stream = dialog.OpenFile())
             {
                 provider.Export(document, stream);
             }
         }
         catch (IOException ex)
         {
             MessageBox.Show(ex.Message);
         }
     }
 }
Example #44
0
        private static void CopyHeaderAndFooter(RadDocument fromDocument, RadDocument toDocument)
        {
            if (!fromDocument.Sections.First.Headers.Default.IsEmpty)
            {
                toDocument.Sections.Last.Headers.Default = fromDocument.Sections.Last.Headers.Default;
            }
            else
            {
                toDocument.Sections.Last.Headers.Default.IsLinkedToPrevious = false;
            }

            if (!fromDocument.Sections.First.Footers.Default.IsEmpty)
            {
                toDocument.Sections.Last.Footers.Default = fromDocument.Sections.Last.Footers.Default;
            }
            else
            {
                toDocument.Sections.Last.Footers.Default.IsLinkedToPrevious = false;
            }
        }
Example #45
0
        private void InsertFragmentFromDocument(RadDocument document)
        {
            if (document != null)
            {
                if (isFirst)
                {
                    isFirst = false;
                }
                else
                {
                    this.radRichTextBox.InsertSectionBreak(SectionBreakType.NextPage);
                }

                document.Selection.SelectAll();
                DocumentFragment frag = new DocumentFragment(document.Selection);
                radRichTextBox.InsertFragment(frag);

                CopySectionProperties(document, radRichTextBox.Document);
            }
        }
Example #46
0
        private static void CopyHeaderAndFooter(RadDocument fromDocument, RadDocument toDocument)
        {
            RadDocumentEditor documentEditor = new RadDocumentEditor(toDocument);
            if (!fromDocument.Sections.First.Headers.Default.IsEmpty)
            {
                documentEditor.ChangeSectionHeader(documentEditor.Document.Sections.First, HeaderFooterType.Default, fromDocument.Sections.Last.Headers.Default);
            }
            else
            {
                documentEditor.ChangeSectionHeaderLinkToPrevious(documentEditor.Document.Sections.Last, HeaderFooterType.Default, false);
            }

            if (!fromDocument.Sections.First.Footers.Default.IsEmpty)
            {
                documentEditor.ChangeSectionFooter(documentEditor.Document.Sections.Last, HeaderFooterType.Default, fromDocument.Sections.Last.Footers.Default);
            }
            else
            {
                documentEditor.ChangeSectionFooterLinkToPrevious(documentEditor.Document.Sections.Last, HeaderFooterType.Default, false);
            }
        }
Example #47
0
        private void InsertFragmentFromDocument(RadDocument document)
        {
            if (document != null)
            {
                if (isFirst)
                {
                    isFirst = false;
                }
                else
                {
                    radRichTextBox.Document.InsertSectionBreak(radRichTextBox.Document.CaretPosition,
                                           radRichTextBox.Document.CaretPosition.GetCurrentInline().ExtractStyleFromLocalProperties(), SectionBreakType.NextPage);
                }

                document.Selection.SelectAll();
                DocumentFragment frag = document.Selection.CopySelectedDocumentElements();
                document.Selection.Clear();
                radRichTextBox.Document.InsertFragment(frag);

                CopySectionProperties(document, radRichTextBox.Document);
            }
        }
Example #48
0
        private static void ShowPrintPreviewDialog(RadDocument document, IDocumentFormatProvider provider)
        {
            PrintPreview printPreview = new PrintPreview(document, provider);

            RadWindow window = new RadWindow();
            window.Content = printPreview;
            window.Header = "Print Preview";
            window.Height = 400;
            window.Width = 500;
#if SILVERLIGHT
            window.WindowStartupLocation = Telerik.Windows.Controls.WindowStartupLocation.CenterScreen;
#else
            window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
#endif
            window.Show();
        }
Example #49
0
 private void mergeDocuments(RadDocument tempDoc, Section prevSection = null)
 {
     foreach (Section sect in tempDoc.Sections)
     {
         Section copySection = sect.CreateDeepCopy() as Section;
         tempDoc.Sections.Remove(sect);
         if (prevSection != null)
             doc.Sections.AddAfter(prevSection, copySection);
         else
             doc.Sections.Add(copySection);
     }
 }
        private void AddPageFooter()
        {
            RadDocument document = new RadDocument();
            Section sectionf = new Section();
            Paragraph paragraphPageField = new Paragraph() { TextAlignment = RadTextAlignment.Right };
            PageField pageField = new PageField() { DisplayMode = FieldDisplayMode.Result };
            FieldRangeStart pageFieldStart = new FieldRangeStart();
            pageFieldStart.Field = pageField;
            FieldRangeEnd pageFieldEnd = new FieldRangeEnd();
            pageFieldEnd.Start = pageFieldStart;

            paragraphPageField.Inlines.Add(pageFieldStart);
            paragraphPageField.Inlines.Add(pageFieldEnd);

            FieldRangeStart numPagesFieldStart = new FieldRangeStart();
            numPagesFieldStart.Field = new NumPagesField() { DisplayMode = FieldDisplayMode.Result };
            FieldRangeEnd numPagesFieldEnd = new FieldRangeEnd();
            numPagesFieldEnd.Start = numPagesFieldStart;

            paragraphPageField.Inlines.Add(new Span("/"));
            paragraphPageField.Inlines.Add(numPagesFieldStart);
            paragraphPageField.Inlines.Add(numPagesFieldEnd);

            sectionf.Blocks.Add(paragraphPageField);
            document.Sections.Add(sectionf);

            Document.Sections.First.Footers.Default.Body = document;

            //Document.Sections.Last.Blocks.AddAfter(Document.Sections.Last.Blocks.Last, paragraphPageField);
            //Document.Sections.Last.Footers.Default.Body.InsertFragment(new DocumentFragment(document));
        }
 private void SetupNewDocument(RadDocument document)
 {
     document.LayoutMode = DocumentLayoutMode.Flow;
     //document.ParagraphDefaultSpacingAfter = 10;
     document.SectionDefaultPageMargin = new Padding(95);
 }
        private static RadDocument CreateDocument(int seed)
        {
            var document = new RadDocument();
            var section = new Section();
            var paragraph1 = new Paragraph();
            section.Blocks.Add(paragraph1);
            var paragraph2 = new Paragraph();
            paragraph2.TextAlignment = Telerik.Windows.Documents.Layout.RadTextAlignment.Center;
            var span1 = new Span("Thank you for choosing Telerik");
            paragraph2.Inlines.Add(span1);
            var span2 = new Span();
            span2.Text = " RadDesktopAlert!";
            span2.FontWeight = FontWeights.Bold;
            paragraph2.Inlines.Add(span2);
            section.Blocks.Add(paragraph2);
            var rand = new Random(seed);
            var paragraph3 = new Paragraph();
            var span3 = new Span(content[rand.Next(content.Count)]);
            paragraph3.Inlines.Add(span3);
            section.Blocks.Add(paragraph3);
            section.Blocks.Add(new Paragraph());
            document.Sections.Add(section);

            return document;
        }
 public DocumentSelectReplaceStateService(RadDocument document, Action resetStateCallBack)
 {
     this.document = document;
     this.resetStateCallBack = resetStateCallBack;
     this.SubscribeForDocumentEvents();
 }
Example #54
0
        private void compileDocument()
        {
            //doc.LineSpacing = 12;
            /*
            Paragraph paragraph1 = new Paragraph();
            Stream stream = Application.GetResourceStream(new Uri(@"/RadRichTextBox-Getting-Started;component/Images/RadRichTextBox.png", UriKind.RelativeOrAbsolute)).Stream;
            Size size = new Size(236, 50);
            ImageInline imageInline = new ImageInline(stream, size, "png");
            paragraph1.Inlines.Add(imageInline);
            section.Blocks.Add(paragraph1);
            */
            // вид документа:
            // предыстория, на отдельной странице (потом разрыв)
            // имя персонажа большими буквами посередине страницы
            // описание, сюжет
            // список целей, ненумерованным списком
            // список предметов (если есть), нумерованным списком
            // правила игры

            doc = new RadDocument();
            doc.MergeSpansWithSameStyles();
            doc.ParagraphDefaultSpacingAfter = 0;
            doc.ParagraphDefaultSpacingBefore = 0;
            Padding padding = new System.Windows.Forms.Padding(0, 20, 100, 60);
            doc.SectionDefaultPageMargin = padding;
            //doc.SectionDefaultPageMargin.
            //doc.DefaultPageLayoutSettings.Width = 200;
            //doc.DefaultPageLayoutSettings.Height = 250;
            RadDocument tempDoc = new RadDocument();

            // **** Prehistory***********
            tempDoc = htmlProvider.Import(prehistory.writtenText);
            mergeDocuments(tempDoc);
            doc.CaretPosition.MoveToLastPositionInDocument();
            doc.InsertPageBreak();

            // **** Person Name ***********
            Section section = new Section();
            Paragraph paragraph1 = new Paragraph();
            paragraph1.TextAlignment = Telerik.WinControls.RichTextBox.Layout.RadTextAlignment.Center;
            Span span1 = new Span(chosenPerson.getName());
            span1.FontSize = 24;
            span1.FontStyle = TextStyle.Bold;
            span1.UnderlineType = Telerik.WinControls.RichTextBox.UI.UnderlineType.Wave;
            paragraph1.Inlines.Add(span1);
            section.Blocks.Add(paragraph1);
            doc.Sections.Add(section);

            // **** Person's description***********
            tempDoc = htmlProvider.Import(chosenPerson.description);
            mergeDocuments(tempDoc, section);

            // **** Aim list***********
            BulletedList aimList = new BulletedList(char.ConvertFromUtf32(0x25CF)[0] , doc);
            Section section2 = new Section();
            Paragraph par2 = new Paragraph();
            doc.CaretPosition.MoveToLastPositionInDocument();
            doc.InsertLineBreak();
            Span span2 = new Span("Your Aims:");
            par2.Inlines.Add(span2);
            section2.Blocks.Add(par2);

            foreach (int aimID in chosenPerson.aimsId)
            {
                CAim aim = aimManager.getAim(aimID);
                Paragraph par = new Paragraph();
                Span span = new Span(aim.getName());
                if (aim.description != "")
                    span.Text += " (" + aim.description + ")";
                par.Inlines.Add(span);
                par.LineSpacingType = LineSpacingType.AtLeast;
                aimList.AddParagraph(par);
                section2.Blocks.Add(par);
            }
            doc.Sections.Add(section2);

            // **** Item list***********
            if (chosenPerson.itemsId.Count > 0)
            {
                NumberedList itemList = new NumberedList(doc);
                Section section3 = new Section();
                Paragraph par3 = new Paragraph();
                Span span3 = new Span("Your Items:");
                par3.Inlines.Add(span3);
                section3.Blocks.Add(par3);

                foreach (int itemID in chosenPerson.itemsId)
                {
                    CItem item = itemManager.getItem(itemID);
                    Paragraph par = new Paragraph();
                    Span span = new Span(item.getName());
                    if (item.description != "")
                        span.Text += " (" + item.description + ")";
                    par.Inlines.Add(span);
                    par.LineSpacingType = LineSpacingType.AtLeast;
                    itemList.AddParagraph(par);
                    section3.Blocks.Add(par);
                }
                doc.Sections.Add(section3);
            }

            // **** Rules***********
            doc.CaretPosition.MoveToLastPositionInDocument();
            doc.InsertLineBreak();
            tempDoc = htmlProvider.Import(rules.writtenText);
            mergeDocuments(tempDoc, doc.Sections.Last);
        }
 public override void Export(RadDocument document, Stream output)
 {
     throw new NotSupportedException();
 }
Example #56
0
        private void CreateDocument()
        {
            RadDocument document = new RadDocument();
            Section section = new Section();

            Paragraph paragraph1 = new Paragraph();
            Stream stream = Application.GetResourceStream(new Uri(imagePath, UriKind.RelativeOrAbsolute)).Stream;
            Size size = new Size(236, 50);
            ImageInline imageInline = new ImageInline(stream, size, "png");
            paragraph1.Inlines.Add(imageInline);
            section.Blocks.Add(paragraph1);

            Paragraph paragraph2 = new Paragraph();
            paragraph2.TextAlignment = Telerik.Windows.Documents.Layout.RadTextAlignment.Center;
            Span span1 = new Span("Thank you for choosing Telerik");
            paragraph2.Inlines.Add(span1);

            Span span2 = new Span();
            span2.Text = " RadRichTextBox!";
            span2.FontWeight = FontWeights.Bold;
            paragraph2.Inlines.Add(span2);
            section.Blocks.Add(paragraph2);

            Paragraph paragraph3 = new Paragraph();
            Span span3 = new Span("RadRichTextBox");
            span3.FontWeight = FontWeights.Bold;
            paragraph3.Inlines.Add(span3);

            Span span4 = new Span(" is a control that is able to display and edit rich-text content including formatted text arranged in pages, paragraphs, spans (runs) etc.");
            paragraph3.Inlines.Add(span4);
            section.Blocks.Add(paragraph3);

            Table table = new Table();
            table.LayoutMode = TableLayoutMode.AutoFit;
            table.StyleName = RadDocumentDefaultStyles.DefaultTableGridStyleName;

            TableRow row1 = new TableRow();

            TableCell cell1 = new TableCell();
            Paragraph p1 = new Paragraph();
            Span s1 = new Span();
            s1.Text = "Cell 1";
            p1.Inlines.Add(s1);
            cell1.Blocks.Add(p1);
            row1.Cells.Add(cell1);

            TableCell cell2 = new TableCell();
            Paragraph p2 = new Paragraph();
            Span s2 = new Span();
            s2.Text = "Cell 2";
            p2.Inlines.Add(s2);
            cell2.Blocks.Add(p2);
            row1.Cells.Add(cell2);
            table.Rows.Add(row1);

            TableRow row2 = new TableRow();

            TableCell cell3 = new TableCell();
            cell3.ColumnSpan = 2;
            Paragraph p3 = new Paragraph();
            Span s3 = new Span();
            s3.Text = "Cell 3";
            p3.Inlines.Add(s3);
            cell3.Blocks.Add(p3);
            row2.Cells.Add(cell3);
            table.Rows.Add(row2);

            section.Blocks.Add(table);
            section.Blocks.Add(new Paragraph());
            document.Sections.Add(section);

            this.radRichTextBox.Document = document;
        }
 private void LoadRadDocument()
 {
     this.radDocument = this.ImportRadDocument(SampleDocumentPath);
     this.SetupNewDocument(this.radDocument);
     this.editor.Document = this.radDocument;
 }
Example #58
0
        /// <summary>
        /// Determines whether the specified document has spelling errors.
        /// </summary>
        /// <param name="document">
        /// The document.
        /// </param>
        /// <param name="culture">
        /// The culture.
        /// </param>
        /// <returns>
        /// The asynchronous task.
        /// </returns>
        public async Task<bool> HasErrors(RadDocument document, CultureInfo culture)
        {
            if (document == null)
                throw new ArgumentNullException("document");

            if (culture == null)
                throw new ArgumentNullException("culture");

            var getUserDictionaryTask = GetUserDictionaryAsync();
            var getDictionaryTask = GetDictionaryAsync(culture);
            var getIgnoredWordsTask = GetIgnoredWordsAsync();

            await TaskEx.WhenAll(getUserDictionaryTask, getDictionaryTask, getIgnoredWordsTask);

            var userDictionary = getUserDictionaryTask.Result;
            var dictionary = getDictionaryTask.Result;
            var ignoredWords = getIgnoredWordsTask.Result;

            var spellChecker = new DocumentSpellChecker(userDictionary);

            try
            {
                if (dictionary != null)
                {
                    spellChecker.AddDictionary(dictionary, culture);
                    spellChecker.RemoveCustomDictionary(culture);
                }

                spellChecker.SpellCheckingCulture = culture;

                var proofingManager = new DocumentProofingManager(document, spellChecker, ignoredWords);

                using (var position = new DocumentPosition(document))
                {
                    var nextErrorWord = proofingManager.GetNextErrorWord(position);

                    return nextErrorWord != null;
                }
            }
            finally
            {
                spellChecker.RemoveCustomDictionary(CultureInfo.InvariantCulture);
            }
        }
        private RadDocument CreateFormattedDocument(string text, string fileFormat)
        {
            RadDocument document = new RadDocument();
            document.LayoutMode = DocumentLayoutMode.Flow;
            document.SectionDefaultPageMargin = new Padding(25);

            Section section = new Section();
            document.Sections.Add(section);

            Tokenizer tokenizer = new Tokenizer();
            List<Token> tokens = tokenizer.TokenizeCode(text, fileFormat);

            Paragraph currentParagraph = new Paragraph();
            currentParagraph.SpacingAfter = 0;
            section.Blocks.Add(currentParagraph);
            foreach (Token token in tokens)
            {
                string[] lines = Regex.Split(token.Value, DocumentEnvironment.NewLine);

                bool createParagraph = false;
                foreach (string line in lines)
                {
                    if (createParagraph)
                    {   
                        currentParagraph = new Paragraph();
                        currentParagraph.SpacingAfter = 0;
                        section.Blocks.Add(currentParagraph);
                    }
                    createParagraph = true;

                    if (!string.IsNullOrEmpty(line))
                    {
                        Span span = token.GetSpanStyle();
                        span.Text = line;
                        currentParagraph.Inlines.Add(span);
                    }
                }
            }
            
            return document;
        }
Example #60
0
        private RadDocument GenerateRadDocument()
        {
            var export = pivot.GenerateExport();
            int rowCount = export.RowCount;
            int columnCount = export.ColumnCount;

            RadDocument document = new RadDocument();
            document.SectionDefaultPageMargin = new Telerik.Windows.Documents.Layout.Padding(10);
            document.LayoutMode = DocumentLayoutMode.Paged;
            document.SectionDefaultPageOrientation = PageOrientation.Landscape;
            document.Style.SpanProperties.FontFamily = pivot.FontFamily;
            document.Style.SpanProperties.FontSize = pivot.FontSize;
            document.Style.ParagraphProperties.SpacingAfter = 0;

            var section = new Telerik.Windows.Documents.Model.Section();
            document.Sections.Add(section);
            section.Blocks.Add(new Telerik.Windows.Documents.Model.Paragraph());

            var table = new Telerik.Windows.Documents.Model.Table(rowCount, columnCount);
            section.Blocks.Add(table);

            var tableRows = table.Rows.ToArray();
            foreach (var cellInfo in export.Cells)
            {
                int rowStartIndex = cellInfo.Row;
                int rowEndIndex = rowStartIndex + cellInfo.RowSpan - 1;
                int columnStartIndex = cellInfo.Column;
                int columnEndIndex = columnStartIndex + cellInfo.ColumnSpan - 1;

                var value = cellInfo.Value;
                var text = Convert.ToString(value);
                if (!string.IsNullOrWhiteSpace(text))
                {
                    var cells = tableRows[rowStartIndex].Cells.ToArray();
                    var cell = cells[columnStartIndex];
                    Paragraph paragraph = new Paragraph();
                    cell.Blocks.Add(paragraph);
                    var span = new Span(text);
                    paragraph.Inlines.Add(span);
                    paragraph.TextAlignment = GetTextAlignment(cellInfo.TextAlignment);

                    if (cellInfo.FontWeight.HasValue)
                    {
                        span.FontWeight = cellInfo.FontWeight.Value;
                    }

                    Color foreColor;
                    if (GetColor(cellInfo.Foreground, out foreColor))
                    {
                        span.ForeColor = foreColor;
                    }

                    cell.VerticalAlignment = GetVerticalAlignment(cellInfo.VerticalAlignment);
                    paragraph.LeftIndent = cellInfo.Indent * 20;
                }

                var borderThickness = cellInfo.BorderThickness;
                var borderBrush = cellInfo.BorderBrush;
                var background = cellInfo.Background;

                Color backColor;
                bool hasBackground = GetColor(cellInfo.Background, out backColor);

                if (cellInfo.RowSpan > 1 && cellInfo.ColumnSpan > 1)
                {
                    for (int k = rowStartIndex; k <= rowEndIndex; k++)
                    {
                        var cells = tableRows[k].Cells.ToArray();
                        for (int j = columnStartIndex; j <= columnEndIndex; j++)
                        {
                            var cell = cells[j];
                            if (hasBackground)
                            {
                                cell.Background = backColor;
                            }

                            cell.Borders = GetCellBorders(borderThickness, borderBrush, cell.Borders, k, rowStartIndex, rowEndIndex, j, columnStartIndex, columnEndIndex, hasBackground);
                        }

                    }
                }
                else if (cellInfo.RowSpan > 1)
                {
                    for (int j = rowStartIndex; j <= rowEndIndex; j++)
                    {
                        // TODO: check when ColumnSpan > 1;
                        var cell = tableRows[j].Cells.ToArray()[columnStartIndex];

                        Position position = j == rowStartIndex ? Position.First : ((j == rowEndIndex) ? Position.Last : Position.Middle);

                        cell.Borders = GetCellBorders(borderThickness, borderBrush, position, cell.Borders, true, cellInfo.Background != null);
                        if (hasBackground)
                        {
                            cell.Background = backColor;
                        }
                    }
                }
                else if (cellInfo.ColumnSpan > 1)
                {
                    var cells = tableRows[rowStartIndex].Cells.ToArray();
                    for (int j = columnStartIndex; j <= columnEndIndex; j++)
                    {
                        // TODO: check when RowSpan > 1;
                        var cell = cells[j];

                        Position position = j == columnStartIndex ? Position.First : ((j == columnEndIndex) ? Position.Last : Position.Middle);
                        if (hasBackground)
                        {
                            cell.Background = backColor;
                        }

                        cell.Borders = GetCellBorders(borderThickness, borderBrush, position, cell.Borders, false, hasBackground);
                    }
                }
            }

            return document;
        }