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

Error when .Print(...PrintMode.Native)

3 Answers 108 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Dominic
Top achievements
Rank 1
Dominic asked on 23 Oct 2012, 09:20 AM

I need to print a simple text document from my Silverlight 4 application and am trying to use the RadRichTextBox control (version 2012.2.912.1040) to do this.

It works fine when I use PrintMode.Html except that it prints a header and footer on the document (I am printing onto a certificate - i.e. student name, qualification, etc - so I do not want this). I can't find any documentation on the Print method, but from Googling around it appears that if I use PrintMode.Native it should print without the header and footer. However, when I attempt to do this I get an "Object reference not set to an instance of an object" error.

Any help/advice would be greatly appreciated.

3 Answers, 1 is accepted

Sort by
0
Petya
Telerik team
answered on 24 Oct 2012, 03:08 PM
Hi Dominic,

There are two common problems that occur when printing with the Silverlight version of RadRichtextBox:
  • The RadRichTextBox which contains the document you are trying to print has to be in the Visual Tree. This means that the editor has to have its Visibility set to Visible. If you do not wish to show the RadRichtextBox in your application, you can set its Height to 0.
  • The second issue that commonly arises is in regard to Silverlight's security restriction policy. Basically, the printing dialog must be shown as a result of a user-instantiated action. You can find more information on the matter in MSDN article. What I would suggest for your application logic is to make sure the document you are trying to print is created by, for example, showing it in a print preview window. Then call the actual Print() method as a result of a button click.

I hope this information is helpful. 
 
Greetings,
Petya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Dominic
Top achievements
Rank 1
answered on 25 Oct 2012, 09:36 AM
Many thanks Petya, that's done the trick.

Could I ask a couple of follow-up questions:
1) is there a way to force the Print from the PrintPreview screen to use the PrintMode.Native method as well?
2) is there anywhere where all the properties and methods of your controls are fully documented - all I can find online is this (which explains some but not all of the features - e.g. there is nothing on printing)?
0
Petya
Telerik team
answered on 26 Oct 2012, 08:51 AM
Hello Dominic,

I apologize for misleading you.

If I understand correctly, you have tried printing by calling the PrintPreview() method of RadRichTextBox and clicking the button in the shown window. What I meant by print preview was not that, since the PrintPreview() method executes the same logic as the one executed when printing using HTML PrintMode. That said, it is not possible to use this print preview and Native mode with this approach.

My idea was to make sure your document is ready by, for example, showing it in a RadRichTextBox which is with limited editing capacities or read only.

When it comes to the documentation, the link you found is the one pointing to our online help. We constantly try to improve it and your feedback is valuable to us. In regard to printing - we've already added an article explaining the best approach for building a document in code-behind and printing it. It will be included in the next documentation version later today in the HowTo section. If you have any other suggestions please share them with us here or send us your feedback at documentation@telerik.com. Thank you!

I hope this makes things clearer. Please, get back to us if you have additional comments or questions.

Kind regards,
Petya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

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