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

[Solved] Best Approach For Printing a large RadRichTextBox inside a UserControl

7 Answers 256 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Stephen
Top achievements
Rank 1
Stephen asked on 09 Jun 2011, 01:16 AM
Hi,

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

Sort by
0
Iva Toteva
Telerik team
answered on 13 Jun 2011, 03:51 PM
Hello Stephen,
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:
  1. The printing must happen on the UI thread;
  2. The rich text box must be added to the visual tree at the time the printing is invoked;
  3. It is quite slow for documents greater than a few pages.
Another option is to use HTML printing, which exports the document to HTML and uses the browser to print the document. Again, the whole document is printed and not just what is seen in the view port. With it, it you don't have much control over the way the document content is allocated between the pages and there are headers/footers which the browser puts (showing the number of pages and the name of the document), but there are no performance issues or other requirements.
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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Stephen
Top achievements
Rank 1
answered on 14 Jun 2011, 01:53 AM
Hello Iva,

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
0
Iva Toteva
Telerik team
answered on 16 Jun 2011, 02:13 PM
Hello 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.

Greetings,
Iva
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Stephen
Top achievements
Rank 1
answered on 16 Jun 2011, 10:39 PM
Hello Iva,

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 :(.
0
Vesko
Telerik team
answered on 22 Jun 2011, 12:25 PM
Hi Stephen,
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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Allen
Top achievements
Rank 2
Iron
Veteran
answered on 15 Jul 2011, 01:58 PM
Are these headers and footers declarative and runtime-customizable?  Assuming so, I need them right now for a project.  The options for doing headers and footers with my current version of the WPF RadRichTextBox control seem very klutzy.

Please advise.

Thank you.
0
Boby
Telerik team
answered on 20 Jul 2011, 09:49 AM
Hi Allen,
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>
The main properties that affects the appearance of the headers/footers are as follows:
  • 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!

Tags
RichTextBox
Asked by
Stephen
Top achievements
Rank 1
Answers by
Iva Toteva
Telerik team
Stephen
Top achievements
Rank 1
Vesko
Telerik team
Allen
Top achievements
Rank 2
Iron
Veteran
Boby
Telerik team
Share this question
or