RadDocument table color alteration on preview

3 posts, 1 answers
  1. xamlcat
    xamlcat avatar
    4 posts
    Member since:
    Jan 2013

    Posted 25 Oct 2013 Link to this post


    I have a problem printing tables from a RadDocument. Take the example below, where the table has two rows, a header which has a black background and white text and a data row, which has white background and black text.
    The preview is showed ok, but when printing both rows have white background and black text.
    using System;
    using System.Linq;
    using System.Windows.Controls;
    using System.Windows.Media;
    using Telerik.Windows.Controls;
    using Telerik.Windows.Documents.FormatProviders;
    using Telerik.Windows.Documents.FormatProviders.Html;
    using Telerik.Windows.Documents.Model;
    using Telerik.Windows.Documents.UI;
    namespace printingTest
        public partial class MainPage : UserControl
            public MainPage()
            public void PrintPreview()
                DocumentFormatProvidersManager.RegisterFormatProvider(new HtmlFormatProvider());
                var printingRichTextBox = new RadRichTextBox();
                RadDocument document = CreateDocumentHeader();
                printingRichTextBox.Document = document;
                printingRichTextBox.Print(string.Empty, PrintMode.Html);
            private static RadDocument CreateDocumentHeader()
                RadDocument document = new RadDocument();
                Table table = new Table();
                table.Borders = new TableBorders(new Telerik.Windows.Documents.Model.Border(1, BorderStyle.Single, Colors.Black));
                TableRow headerRow = new TableRow();
                TableCell cellHeader = new TableCell();
                cellHeader.Background = Colors.Black;
                Paragraph paragraphHeader = new Paragraph();
                Span spanHeader = new Span();
                spanHeader.ForeColor = Colors.White;
                spanHeader.Text = "SAMPLE HEADER TEXT - SAMPLE HEADER TEXT";
                TableRow dataRow = new TableRow();
                TableCell cellData = new TableCell();
                cellData.Background = Colors.White;
                Paragraph paragraphData = new Paragraph();
                Span spanData = new Span();
                spanData.ForeColor = Colors.Black;
                spanData.Text = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit";
                Paragraph tableIsDangerousToGoAlone1 = new Paragraph();
                Paragraph tableIsDangerousToGoAlone2 = new Paragraph();
                Section section = new Section();
                return document;

    Why this is happening? How could it be avoided?

  2. Answer
    Petya avatar
    990 posts

    Posted 30 Oct 2013 Link to this post


    Thank you for contacting us with this!

    Would you mind sharing with us why you want to use HTML printing in your project? HTML printing was introduced in a previous version of the control as a way to overcome a performance hit in Silverlight 4. However, the issue is not present in Silverlight 5 which is why we usually recommend Native printing instead.

    To further explain, what this mode does is to export the document to HTML and pass it to the browser which handles the printing itself. The preview window shows the HTML content as expected, meaning that in this case the document is exported properly. However, for some reason the browser printing strips the background of the cell. I tried the same scenario but using Native printing and everything seems to work as expected.

    The print preview functionality uses the same mechanism as HTML printing. In case you want to take advantage of the feature but use Native printing I suggest you create a new window with a read-only RadRichTextBox, show the document in it and invoke Native printing from a button.

    Additionally, please note that for printing to work properly we recommend placing RadRichTextBox in the visual tree of your application. In cases when you do not wish to actually show the document you can place a RadRichTextBox with height 0 in your application.

    I hope this is helpful!

    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. xamlcat
    xamlcat avatar
    4 posts
    Member since:
    Jan 2013

    Posted 30 Oct 2013 Link to this post

    Hello Petya,

    I've tried your recommendation of creating a new window with a read-only RadRichTextBox on it, load the document, and to use a button to invoke the Native printing. With this approach the document was printed correctly, so I'll mark your response as the answer to this thread.
    Thank you very much!

    I forgot to mention it before, the HTML printing was used because it was already in the code I had to maintain, from which I extract the sample project, maybe because of the Silverlight 4 issue you had mentioned, but I really don't know why.

Back to Top