I haven't started this yet, but it is something I need to do and I cannot really see any easy way of doing this at present. I know the RadRichTextBox comes with Print and PrintPreview methods which is great if you just want to print out the represented document. However, I want to print out a UserControl that contains a RadRichTextBox and that RadRichTextBox may span multiple pages when printed.
Looking at the standard Silverlight 4 printing API if I were to attach the PrintPageEventArgs PageVisual I am assuming that I would just get the current state of the RadRichTextBox as it appears on the screen.
I am probably going to need to create a seperate print specific control to use in printing. What I can't quite figure out is how to handle multiple pages inside the RadRichTextBox.
Do I need to cut up the RadDocument with code? If so how do I determine how much space it is going to take up when rendered inside a RadRichTextBox without actually assigning it to a control? As I could imagine this process could be quite performance intensive. Are there any other approaches I could take?
Any advice would be appreciated.
Stephen
7 Answers, 1 is accepted
RadRichTextBox offers two options for printing the document - using Silverlight's printing or using HTML printing. When it comes to the native printing, we have provided an implementation that prints all pages of the document, but there are still lots of Silverlight limitations:
- The printing must happen on the UI thread;
- The rich text box must be added to the visual tree at the time the printing is invoked;
- It is quite slow for documents greater than a few pages.
Please find attached a demo illustrating how you can print the document in either way with the latest version of the control.
Best wishes,
Iva
the Telerik team
Thank you for your reply. I can see through the example that you are printing the RadRichTextBox through the two described mechanism, native and HTML. But you are just printing the RadRichTextBox not the other controls.
In my scenario I want to print a complex visual tree which the RadRichTextBox is part of. The RadRichTextBox may contain more content than can easily fit on the screen so I am trying to figure out the best way to do this.
One option I think I have is to create a printing specific user control which is largely responsible for splitting up the original RadDocument. Call PrintDocument.Print on the user control, and manage the content inside the printed RadRichTextBox when the PrintPage event is fired. This seems like alot of work, and I am not sure how to efficently work out when the RadRichTextBox is 'full' of visible content. I guess just slowly build up the control and check when the VerticalScrollBar is visible on the control?
I could again write a printing specific control and just print the RadRichTextBox all in one hit which would be fine for my purposes, but there would be alot of excess whitespace. For example if I had some header content, the RadRichTextBox, and some footer content there would effectively be page breaks between the RadRichTextBox and the header / footer. Is there any way I could plug into Telerik's existing printing logic for this control? I notice in your example you use a DocumentPrintPresenter, but the only print events I can handle are PrintingStarted and PrintingCompleted, which doesn't give me alot of control.
Any help would be appreciated,
Stephen
We can send you the source code of RadRichTextBox, so that you can see how native printing was implemented for the control and incorporate this logic in your project. If this is how you wish to proceed, please open a support ticket requesting the source.
Are these header and footer controls of yours serving as headers and footers of RadRichTextBox's document? Because if that is the case, we will be introducing headers and footers in the control in the Beta, which is expected in less than a week. We might not manage to squeeze import/export to some formats and printing, but they will be implemented for the official release in mid-July.
Iva
the Telerik team
My use of the terms header and footer was a bit misleading. What I really meant was content that I want printed which above and below the RadRichTextBox content. The header and footer functionality you are implementing in the future sounds great, but unfortunately doesn't really meet my needs.
My license gives me access to the source code, so I'll download it and have a look at how you guys implemented printing, hopefully it won't be too hard to put something together that meets my needs :(.
Thanks for your questions! For your information in latest versions of RadRichTextBox the source code was distributed separately on demand, so in order to obtain it you should open a support ticket where we can send it to you privately.
Please don't hesitate to contact us if you need any further assistance when you get the source code.
Regards,
Vesko
the Telerik team
Please advise.
Thank you.
Please excuse us for the missing documentation about headers and footers – we are actively working on it.
Headers and footers can be set in both XAML and code-behind:
<telerik:RadRichTextBox Name="radRichTextBox" LayoutMode="Paged"> <telerik:RadRichTextBox.Document> <telerik:RadDocument> <telerik:Section> <telerik:Section.Headers> <telerik:Headers> <telerik:Headers.Default> <telerik:Header> <telerik:Header.Body> <telerik:RadDocument> <telerik:Section> <telerik:Paragraph> <telerik:Span Text="Default Header" /> </telerik:Paragraph> </telerik:Section> </telerik:RadDocument> </telerik:Header.Body> </telerik:Header> </telerik:Headers.Default> </telerik:Headers> </telerik:Section.Headers> </telerik:Section> </telerik:RadDocument> </telerik:RadRichTextBox.Document></telerik:RadRichTextBox>- Section.Headers
- Section.Footers
- RadDocument.HasDifferentEvenAndOddHeadersFooters
- Section.HasDifferentFirstPageHeaderFooter
- Section.HeaderTopMargin
- Section.FooterBottomMargin
Don't hesitate to contact us if you have other questions.
All the best,Boby
the Telerik team
Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!
