This is a migrated thread and some comments may be shown as answers.

RadDocument table color alteration on preview

2 Answers 151 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
xamlcat
Top achievements
Rank 1
xamlcat asked on 25 Oct 2013, 11:58 AM
Hi,

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()
        {
            InitializeComponent();
 
            PrintPreview();
        }
 
        public void PrintPreview()
        {
            DocumentFormatProvidersManager.RegisterFormatProvider(new HtmlFormatProvider());
 
            var printingRichTextBox = new RadRichTextBox();
 
            RadDocument document = CreateDocumentHeader();
 
            printingRichTextBox.Document = document;
            printingRichTextBox.Print(string.Empty, PrintMode.Html);
 
            printingRichTextBox.PrintPreview();
        }
 
 
        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";
            paragraphHeader.Inlines.Add(spanHeader);
            cellHeader.Blocks.Add(paragraphHeader);
            headerRow.Cells.Add(cellHeader);
 
            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";
            paragraphData.Inlines.Add(spanData);
            cellData.Blocks.Add(paragraphData);
            dataRow.Cells.Add(cellData);
 
 
 
            table.Rows.Add(headerRow);
            table.Rows.Add(dataRow);
 
            Paragraph tableIsDangerousToGoAlone1 = new Paragraph();
            Paragraph tableIsDangerousToGoAlone2 = new Paragraph();
 
            Section section = new Section();
 
            section.Blocks.Add(tableIsDangerousToGoAlone1);
            section.Blocks.Add(table);
            section.Blocks.Add(tableIsDangerousToGoAlone2);
 
            document.Sections.Add(section);
 
            return document;
        }
 
    }
}

Why this is happening? How could it be avoided?

Thanks.

2 Answers, 1 is accepted

Sort by
0
Accepted
Petya
Telerik team
answered on 30 Oct 2013, 11:06 AM
Hello,

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!

Regards,
Petya
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
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 >>
0
xamlcat
Top achievements
Rank 1
answered on 30 Oct 2013, 12:27 PM
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.

Regards.
Tags
RichTextBox
Asked by
xamlcat
Top achievements
Rank 1
Answers by
Petya
Telerik team
xamlcat
Top achievements
Rank 1
Share this question
or