I have a problem when i m trying printing my Document in RadRichTextBox.
This is my scenario:
I Create a user control which has a RichTextBox control in its LayoutRoot. I Create the document dynamically and set it to the Document property of RadRichtextBox. The problem happens when I call the print method of RadRichTextBox. I got this exeption:
"Object reference not set to an instance of an object
at Telerik.Windows.Controls.RadRichTextBox.Print(PrintSettings printSettings)
at Telerik.Windows.Controls.RadRichTextBox.Print(String documentName, PrintMode mode)
at UIBase.Controls.RichTextBoxControl.Print(String printName, PrintMode printMode)
at UIBase.Controls.RibbonBarControl.mainBtnPrint_Click(Object sender, RoutedEventArgs e) "
I Have checked, the document contains all sections i created and the reference to the RaddRichTextBox is not null. Is there any particular settings i have to do in order to make it printing??
Thanks for your Help.
Alino
11 Answers, 1 is accepted
We have encountered this problem only when the rich text box is not added to the visual tree. Native printing works on the UI Thread and cannot print UIElements that are not added to the visual tree.
As a workaround, you can add the rich text box to the visual tree before printing the document and remove it afterwards.
If the RichTextBox is in the visual tree and you are still experiencing difficulties printing the document, we would appreciate some additional information on your scenario or, preferrably, a sample project. You can attach a demo project in a support ticket of type General Feedback.
Iva
the Telerik team
Thanks for your wonderfull support. I solved my problem. Before I added my richTextBox in a userControl and add the userControl in the visual tree. This way did not work. But by adding directly my richtextBox in the visual tree, the exception diseappeared.
Best regards.
Alino
I have this problem too
here is my Xamel code.
whaqt should i do?
<
navigation:Page
xmlns:sdk
=
"http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
x:Class
=
"Tahrireh.Views.EnterNewsPage"
xmlns:docUI
=
"clr-namespace:Telerik.Windows.Documents.UI;assembly=Telerik.Windows.Documents"
mc:Ignorable
=
"d"
xmlns:navigation
=
"clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
Title
=
"EnterNewsPage Page"
d:DesignHeight
=
"630"
d:DesignWidth
=
"984"
xmlns:riaControls
=
"clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.DomainServices"
xmlns:my
=
"clr-namespace:Tahrireh.Web.Models"
xmlns:my1
=
"clr-namespace:Tahrireh.Web.Services"
xmlns:my2
=
"clr-namespace:Tahrireh.Controls"
xmlns:telerik
=
"http://schemas.telerik.com/2008/xaml/presentation"
xmlns:my3
=
"clr-namespace:Telerik.Windows.Documents.FormatProviders.Xaml;assembly=Telerik.Windows.Documents.FormatProviders.Xaml"
>
<
Grid
x:Name
=
"LayoutRoot"
Background
=
"White"
Height
=
"630"
Width
=
"{StaticResource ViewPagesWidth}"
>
<
StackPanel
Height
=
"Auto"
HorizontalAlignment
=
"Center"
Margin
=
"0,10,0,0"
Name
=
"stackPanel2"
VerticalAlignment
=
"Top"
Width
=
"Auto"
Orientation
=
"Horizontal"
>
<
Button
x:Name
=
"btnEdit"
Style
=
"{StaticResource GlassButtonStyle}"
Background
=
"#FFFF9400"
BorderBrush
=
"#FFFF9400"
Height
=
"50"
Width
=
"50"
Margin
=
"5,0,0,0"
HorizontalAlignment
=
"Center"
VerticalAlignment
=
"top"
ToolTipService.ToolTip
=
"ویرایش"
Cursor
=
"Hand"
RenderTransformOrigin
=
"0.5,0.5"
Click
=
"btnEdit_Click"
>
<
Button.RenderTransform
>
<
CompositeTransform
/>
</
Button.RenderTransform
>
<
Image
Height
=
"32"
Source
=
"/Tahrireh;component/images/edit2.png"
Stretch
=
"Fill"
Width
=
"32"
/>
</
Button
>
<
Button
x:Name
=
"btnPrint"
Style
=
"{StaticResource GlassButtonStyle}"
Background
=
"#FFFF9400"
BorderBrush
=
"#FFFF9400"
Height
=
"50"
Width
=
"50"
Margin
=
"5,0,0,0"
HorizontalAlignment
=
"Center"
VerticalAlignment
=
"top"
ToolTipService.ToolTip
=
"چاپ"
Cursor
=
"Hand"
RenderTransformOrigin
=
"0.5,0.5"
Click
=
"btnPrint_Click"
>
<
Button.RenderTransform
>
<
CompositeTransform
/>
</
Button.RenderTransform
>
<
Image
Height
=
"32"
Source
=
"/Tahrireh;component/images/hp_printer.png"
Stretch
=
"Fill"
Width
=
"32"
/>
</
Button
>
</
StackPanel
>
<
Grid
Margin
=
"0,80,0,0"
>
<
riaControls:DomainDataSource
AutoLoad
=
"True"
d:DesignData
=
"{d:DesignInstance my:RawNews, CreateList=true}"
Height
=
"0"
LoadedData
=
"rawNewsDomainDataSource_LoadedData"
Name
=
"rawNewsDomainDataSource"
QueryName
=
"GetRawNewsesQuery"
Width
=
"0"
>
<
riaControls:DomainDataSource.DomainContext
>
<
my1:RawNewsDomainContext
/>
</
riaControls:DomainDataSource.DomainContext
>
</
riaControls:DomainDataSource
>
<
Grid
DataContext
=
"{Binding ElementName=rawNewsDomainDataSource, Path=Data}"
Margin
=
"20,0,20,0"
Name
=
"grid1"
VerticalAlignment
=
"Top"
HorizontalAlignment
=
"Center"
Width
=
"700"
Height
=
"Auto"
FlowDirection
=
"RightToLeft"
>
<
Grid.ColumnDefinitions
>
<
ColumnDefinition
Width
=
"1*"
/>
<
ColumnDefinition
Width
=
"5*"
/>
</
Grid.ColumnDefinitions
>
<
Grid.RowDefinitions
>
<
RowDefinition
Height
=
"Auto"
/>
<
RowDefinition
Height
=
"Auto"
/>
<
RowDefinition
Height
=
"Auto"
/>
<
RowDefinition
Height
=
"Auto"
/>
<
RowDefinition
Height
=
"Auto"
/>
<
RowDefinition
Height
=
"Auto"
/>
</
Grid.RowDefinitions
>
<
sdk:Label
Content
=
"عنوان:"
Grid.Column
=
"0"
Grid.Row
=
"0"
HorizontalAlignment
=
"Left"
Margin
=
"3"
VerticalAlignment
=
"Center"
/>
<
TextBox
Grid.Column
=
"1"
Grid.Row
=
"0"
Height
=
"23"
HorizontalAlignment
=
"Left"
Margin
=
"3"
Name
=
"titleTextBox"
Text
=
"{Binding Path=Title, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true, TargetNullValue=''}"
VerticalAlignment
=
"Center"
Width
=
"420"
/>
<
sdk:Label
Content
=
"توضیحات:"
Grid.Column
=
"0"
Grid.Row
=
"1"
HorizontalAlignment
=
"Left"
Margin
=
"3"
VerticalAlignment
=
"Center"
/>
<
TextBox
Grid.Column
=
"1"
Grid.Row
=
"1"
Height
=
"100"
HorizontalAlignment
=
"Stretch"
Margin
=
"3"
Name
=
"descriptionTextBox"
Text
=
"{Binding Path=Description, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true, TargetNullValue=''}"
VerticalAlignment
=
"Center"
Width
=
"Auto"
AcceptsReturn
=
"True"
TextWrapping
=
"Wrap"
/>
<
sdk:Label
Content
=
"متن:"
Grid.Column
=
"0"
Grid.Row
=
"2"
HorizontalAlignment
=
"Left"
Margin
=
"3"
VerticalAlignment
=
"Center"
Cursor
=
"Hand"
MouseLeftButtonDown
=
"Label_MouseLeftButtonDown"
/>
<
telerik:RadRichTextBox
x:Name
=
"editor"
Background
=
"Transparent"
Grid.Row
=
"2"
Grid.Column
=
"1"
Height
=
"Auto"
IsReadOnly
=
"True"
FlowDirection
=
"LeftToRight"
>
<
telerik:RadRichTextBox.Resources
>
<
Style
TargetType
=
"docUI:Page"
>
<
Setter
Property
=
"Template"
>
<
Setter.Value
>
<
ControlTemplate
TargetType
=
"docUI:Page"
>
<
ContentPresenter
x:Name
=
"PageContentPresenter"
Visibility
=
"Collapsed"
/>
</
ControlTemplate
>
</
Setter.Value
>
</
Setter
>
<
Setter
Property
=
"HorizontalAlignment"
Value
=
"Center"
/>
<
Setter
Property
=
"VerticalAlignment"
Value
=
"Top"
/>
</
Style
>
</
telerik:RadRichTextBox.Resources
>
</
telerik:RadRichTextBox
>
<
sdk:Label
Content
=
"آدرس فیلم:"
Grid.Column
=
"0"
Grid.Row
=
"3"
HorizontalAlignment
=
"Left"
Margin
=
"3"
VerticalAlignment
=
"Center"
/>
<
TextBox
Grid.Column
=
"1"
Grid.Row
=
"3"
Height
=
"23"
HorizontalAlignment
=
"Left"
Margin
=
"3"
Name
=
"movieUrlTextBox"
Text
=
"{Binding Path=MovieUrl, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true, TargetNullValue=''}"
VerticalAlignment
=
"Center"
Width
=
"420"
/>
<
sdk:Label
Content
=
"موضوع:"
Grid.Column
=
"0"
Grid.Row
=
"4"
HorizontalAlignment
=
"Left"
Margin
=
"3"
VerticalAlignment
=
"Center"
/>
<
TextBox
Grid.Column
=
"1"
Grid.Row
=
"4"
Height
=
"23"
HorizontalAlignment
=
"Left"
Margin
=
"3"
Name
=
"tagsTextBox"
Text
=
"{Binding Path=Tags, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true, TargetNullValue=''}"
VerticalAlignment
=
"Center"
Width
=
"420"
/>
<
StackPanel
Grid.ColumnSpan
=
"2"
Grid.Row
=
"5"
Grid.RowSpan
=
"2"
Height
=
"Auto"
HorizontalAlignment
=
"Center"
Name
=
"stackPanel1"
VerticalAlignment
=
"Top"
Width
=
"200"
Orientation
=
"Horizontal"
>
<
Button
Content
=
"ثبت"
Height
=
"23"
HorizontalAlignment
=
"Left"
Margin
=
"10,20,0,0"
Name
=
"btnSave"
VerticalAlignment
=
"Top"
Width
=
"75"
Click
=
"btnSave_Click"
/>
<
Button
Content
=
"انصراف"
Height
=
"23"
HorizontalAlignment
=
"Left"
Margin
=
"10,20,0,0"
Name
=
"btnCancel"
VerticalAlignment
=
"Top"
Width
=
"75"
Click
=
"btnCancel_Click"
/>
</
StackPanel
>
</
Grid
>
</
Grid
>
<
my2:BusyIndicator
Height
=
"Auto"
HorizontalAlignment
=
"Center"
VerticalAlignment
=
"Top"
x:Name
=
"busyIndicator1"
IsBusy
=
"{Binding RelativeSource={RelativeSource Self}, Path=IsBussy}"
>
</
my2:BusyIndicator
>
</
Grid
>
</
navigation:Page
>
We could not reproduce the issue you are observing.
Could you elaborate a bit more on your scenario and implementation, as well as the exception that is thrown.
Some information on the following items can help us assist you further:
1. What version of the controls are you using? There was a bug in native printing in the official Q2 release (2011.2 712), which was fixed in an internal build soon after that. Native printing works OK with the latest version, too - 2011 Q2 SP1 (2011.2 920).
2. Why are you setting the template of the Page?
3. How are you printing the document and is the page shown at the time you invoke the printing?
4. The stack trace of the exception.
Iva
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
1. What version of the controls are you using? There was a bug in native printing in the official Q2 release (2011.2 712), which was fixed in an internal build soon after that. Native printing works OK with the latest version, too - 2011 Q2 SP1 (2011.2 920).
2011.2.712.1040
Should i update Binaries?
Yes, if you change the version of the binaries to the latest internal build or the service pack, the problem should be resolved.
Regards,Iva
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
I updated the binaries and now it works fine.
i have a new question
I have Two input, "Title" and "Text". I'm using RichTextBox for my text editor and i used another textbox for "title". now when i want to print , it just prints the RichTextBox Content, how can i print Title on the above of RichTextBox Content
thanks a lot
RadRichTextBox only supports printing of its own content, so to use it, you can add the title to the document just before printing it, for example:
Span titleSpan =
new
Span(
"Title"
);
titleSpan.FontSize = 30;
Paragraph titleParagraph =
new
Paragraph();
titleParagraph.TextAlignment = RadTextAlignment.Center;
titleParagraph.Inlines.Add(titleSpan);
// this will add the title paragraph before the first block
this
.radRichTextBox.Document.Sections.First.Blocks.AddBefore(
this
.radRichTextBox.Document.Sections.First.Blocks.First, titleParagraph);
this
.radRichTextBox.Print(
"document"
, PrintMode.Html);
Regards,
Boby
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
You're the BEST
I found a new problem.
i use a RTL Language. when i write a rtl text and save it to database and restore it from database, i don't have problem. but when the lenght of the text is long and text editor automatically adds scrollbar, and when i scroll text to down and again to up, the text mixes up and words places changes.
what i should do?
thanks
There is a known issue with editing documents in RTL languages, which has been fixed in the development version and will be released in the upcoming Q3 Beta.
Could you please open a support ticket of type general feedback and attach the document that illustrates the scrolling issue, so that we can check if it has been fixed.
Please, do not forget to include information regarding the version of the controls you are using and the layout mode you are using RadRichTextBox in (Web LayoutMode or Paged LayoutMode).
Looking forward to your reply.
Iva
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>