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.
Thanks.
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.
Why this is happening? How could it be avoided?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;
}
}
}
Thanks.